Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It does not work for iOS #35

Open
i5kender opened this issue Jan 27, 2016 · 4 comments
Open

It does not work for iOS #35

i5kender opened this issue Jan 27, 2016 · 4 comments

Comments

@i5kender
Copy link

i have a one c# web service and i can decript and encript c# webservice, android project and c# client project. but i can not implement pakhee ios code for my ios application. There are a lot of error in ios classes. Could you fix ios classes and give usage example for ios application?

@MVakas
Copy link

MVakas commented Feb 2, 2016

Not working for me for iOS as well. It gives too many errors.

@navneet83
Copy link
Owner

@i5kender @MVakas I had tested all the code provided in this library. Unfortunately, I won't be able to help you with the information you have provided.
What are the errors which you are getting ? Can you create a gist which I can look at ?

@i5kender
Copy link
Author

I have used https://github.com/benoitsan/BBAES classes for ios encrption. I have done. Thanks a lot navneet

@rishbaranwal
Copy link

I am stuck somewhere in between, please help

This is the function I am using to decrypt in iOS

func aesCBCDecrypt(data: Data, keyData: Data) throws -> Data? {
    let keyLength = keyData.count
    let validKeyLengths = [kCCKeySizeAES128, kCCKeySizeAES192, kCCKeySizeAES256]
    if validKeyLengths.contains(keyLength) == false {
        throw AESError.KeyError(("Invalid key length", keyLength))
    }
    var numBytesDecrypted: size_t = 0
    let options   = CCOptions(kCCOptionPKCS7Padding)
    let cryptLength  = size_t(data.count)
    var cryptData = Data(count: cryptLength)

    let cryptStatus = cryptData.withUnsafeMutableBytes {cryptBytes in
        data.withUnsafeBytes {dataBytes in
            keyData.withUnsafeBytes {keyBytes in
                CCCrypt(CCOperation(kCCDecrypt),
                        CCAlgorithm(kCCAlgorithmAES),
                        options,
                        keyBytes, keyLength + 1,
                        keyBytes,
                        dataBytes, data.count,
                        cryptBytes, cryptLength,
                        &numBytesDecrypted)
            }
        }
    }

This is the function I am using to encrypt in .net

public string EncryptData(string textData, string Encryptionkey)
{
RijndaelManaged objrij = new RijndaelManaged
{
//set the mode for operation of the algorithm
Mode = CipherMode.CBC,
//set the padding mode used in the algorithm.
Padding = PaddingMode.PKCS7,
//set the size, in bits, for the secret key.
KeySize = 256,
//set the block size in bits for the cryptographic operation.
BlockSize = 128
};
//set the symmetric key that is used for encryption & decryption.
byte[] passBytes = Encoding.UTF8.GetBytes(Encryptionkey);
//set the initialization vector (IV) for the symmetric algorithm
byte[] EncryptionkeyBytes = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

                //int len = passBytes.Length;
                //if (len > EncryptionkeyBytes.Length)
                //{
                //     len = EncryptionkeyBytes.Length;
                //}
                //Array.Copy(passBytes, EncryptionkeyBytes, len);

                objrij.Key = passBytes;
                objrij.IV = EncryptionkeyBytes;

                //Creates symmetric AES object with the current key and initialization vector IV.   
                ICryptoTransform objtransform = objrij.CreateEncryptor();
                byte[] textDataByte = Encoding.UTF8.GetBytes(textData);
                //Final transform the test string. 
                return Convert.ToBase64String(objtransform.TransformFinalBlock(textDataByte, 0, textDataByte.Length));
         }

I am not getting the expected output.

Input:

Plain text: dd00bd64-38d6-4d68-b0fc-2bc6389ee9b3
key: abcdef0123456789abcdef0123456789

Output:

\u{05}\u{06}ST\u{07}\u{02}\u{06}\u{05}\u{1F}\0\u{0C}Q\0\u{1A}\u{0C}]68-b0fc-2bc6389ee9b3

Any help is appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants