CLI
$ echo -n "TEST1" | openssl enc -aes256 -k FUUU -nosalt -a
bYbkQJcDFZt3y3UQEMbEeg==
iOS
NSString *leSYT = @"bYbkQJcDFZt3y3UQEMbEeg==";
NSData *data = [NSData dataFromBase64String:leSYT];
NSLog(@"%@",[data AES256DecryptWithKey:@"FUUU"]);
iOS doesn't output anything since it failed. What am I missing?
NSData additions: http://pastie.org/426530 // NSData+Base64 by Matt Gallagher
The
-k
option in OpenSSL's enc utility derives an AES key and IV from your passphrase "FUUU". You can use the-p
option to have OpenSSL print the AES256 key and IV that it derived:AES256DecryptWithKey is expecting a 32-byte AES key, as the comments say:
But even if you convert the key string from OpenSSL to a string of bytes (not 64 ASCII characters. 32 bytes), you still won't be able to decrypt it and get your original string back. That's because OpenSSL is using an IV, but AES256DecryptWithKey is not:
(See the NULL being passed for the IV? That's not going to work for you)
So you need to use an encryption and decryption method that both use the same AES key and IV for this to work.