Update: solution found. I will update this question soon with the actual working code and team.
The client encrypts the server-side file using C ++, and I need to decrypt it in the iPhone application.
My client can glue and decrypt on their side, and I can also on the iPhone, but we can not decrypt the file encrypted by each other. I saw a lot of related questions on SO, but no one could help me find an implementation that works the same on both sides.
I want to derive some approximate values that we will take as a general implementation.
I tried to hide the file using openssl and decrypt it using cocoa, but could not.
Here is what I use for encryption:
echo "123456789ABCDEFG" | openssl enc -aes-128-ecb -nosalt -K "41414141414141414141414141414141" -iv 0 > hello.txt.bin
Adding the -p option to the openssl call shows that the expected key and iv are used:
key=41414141414141414141414141414141 iv =00000000000000000000000000000000
And for cocoa decryption (in NSData category):
- (NSData *)AESDecryptWithKey:(NSString *)key { char keyPtr[kCCKeySizeAES128+1];
called as follows:
- (void)testBinaryFileDecryption { NSString *databasePath = [[NSBundle mainBundle] pathForResource:@"hello" ofType:@"txt.bin"]; NSData *data = [NSData dataWithContentsOfFile:databasePath]; NSAssert(nil != data, @"Encrypted data, freshly loaded from file should not be nil"); NSData *plain = [data AESDecryptWithKey:@"AAAAAAAAAAAAAAAA"]; NSAssert(nil != plain, @"Decrypted plain data should not be nil"); NSLog(@"Result: '%@'", [[NSString alloc] initWithData:plain encoding:NSASCIIStringEncoding]); }
Logs of results: Result: '4¨µ¢Ä½Pk£N
Which option did I forget? Is NSData encoding a return of something else than NSASCIIStringEncoding?