This is my java code. Now I want to implement same functionality in Objective-C.
Cipher encryptCipher;
IvParameterSpec i
Well, how big is your key? kCCAlgorithmAES128
and kCCKeySizeAES256
assume different key sizes. I'm assuming that you're using a 16 byte key, because your Java code would throw an exception otherwise. If you're using a 128 bit key, then you should use kCCKeySizeAES128
.
Additionally, you're not passing in any IV, so it will be assumed that the IV is filled with 0x00 bytes, but in Java, you're using the key as IV.
Don't use the key as IV. That diminishes the use of the IV in the first place that is there to randomize the ciphertext. You need to generate a random IV for each encryption and send it along with the ciphertext, for example by prepending it to the ciphertext.
Yes, PKCS#5 padding and PKCS#7 padding are the same thing.