I have seen this thread, and the encryption techniques mentioned there is working well. But not in all cases.
Requirement:
Simple, take one image, encrypt it, and store the encrypted data. Later, get the encrypted data, decrypt it, recreate the original image and show.
What I have done
From the above mentioned thread, I found NSData additions for AES 256 encryption. I tried to use it but with partial success. This is the code
//encryption
NSData *srcData = UIImageJPEGRepresentation(srcImage, 1.0);
NSLog(@"srcData length : %d",[srcData length]);
NSData *encryptedData = [srcData AES256EncryptWithKey:KEY];
NSLog(@"encrypted data length : %d",[encryptedData length]);
........
//later..
//decryption
decryptedImage = [UIImage imageWithData:[encryptedData AES256DecryptWithKey:KEY]];
imageView.image = decryptedImage;
What is happening
For a small image, say image with resolution 48*48, this code is working successfully. But when I run the code in an image with higher resolutions, say 256 * 256, the method AES256EncryptWithKey
failing with error kCCBufferTooSmall
(-4301).
Questions
- Does AES 256 impose any limit on the size (in bytes) of the payload to be encrypted?
- If the answer to first question is YES, then what kind of encryption algorithm to use in iphone, to encrypt image (probably big ones)?
- If the answer to the first question is NO, then why this error?