2

I would like to know how to decrypt some text encrypted on iPhone using AES256 and PKCS7Padding with a PHP function.

I use following Objective-C code.

https://gist.github.com/838614

- (NSString *)AES256EncryptWithKey:(NSString *)key
{
   NSData *plainData = [self dataUsingEncoding:NSUTF8StringEncoding];
   NSData *encryptedData = [plainData AES256EncryptWithKey:key];

   NSString *encryptedString = [encryptedData base64Encoding];

   return encryptedString;
}
Tharindu Madushanka
  • 3,241
  • 7
  • 31
  • 33

1 Answers1

2

The following PHP snippet covers removing PKCS7 padding, which combined with this SO question (but substituting MCRYPT_RIJNDAEL_128 for MCRYPT_RIJNDAEL_256 in your case) should give you what you need.

Community
  • 1
  • 1
jnic
  • 8,695
  • 3
  • 33
  • 47
  • just a little question, in iOS code, we don't really have $iv kind of value in. what does it really mean.. and also about block size parameter to unpad.. thanks a lot for your help... – Tharindu Madushanka Mar 21 '11 at 12:59
  • The IV in this case is the 6th argument to CCCrypt (line 48). More about IVs at Wikipedia (http://en.wikipedia.org/wiki/Initialization_vector). The block size appears to be kCCBlockSizeAES128. – jnic Mar 21 '11 at 16:22