Reputation: 2581
I have used so many libraries and so many functions but can't decrypt it.
NSString *key = @"innoways21897016";
NSString *iv = @"61079821218970166107982121897016";
NSString *encrypted = @"iG5lIZKGevzV3UfhcqOzgA/xwKhAKjB75G1L4Z1s/RU=";
NSData *data = [encrypted dataUsingEncoding:NSUTF8StringEncoding];
NSData *dataDecrypted = [data AES256DecryptWithKey:key andIV:iv];
NSLog(@"decrypt data = %@",dataDecrypted);
NSString *receivedDataDecryptString = [[NSString alloc]initWithData:dataDecrypted encoding:NSUTF8StringEncoding];
NSLog(@"decrypt string = %@",receivedDataDecryptString);
receivedDataDecryptString
always giving me (null) response not a decrypt string.
output will be - "heidi"
Thanks.
Upvotes: 0
Views: 667
Reputation: 112875
There are some errors and potential errors:
You are specifying AES with a 256-bit key (AES256DecryptWithKey
) but supplying a 128-bit (16-byte) key. Either specify AES with a 128-bit key or provide a 256-bit key.
AES has a block size of 16-bytes you are supplying a 32-byte IV, the IV should be 16-Bytes.
Perhaps you have the key and IV reversed.
You are supplying the encrypted data in Base64 encoding, the encryption method probably expects the input to be NSData
or NSString. The length must be a multiple of the block size, 16-bytes for AES, supplying encrypted data of the wrong length is one of the few ways you will get an error from CCCrypt
which the decryption method is most likely using.
You have not provided the expected decrypted result, this makes testing a solution difficult.
The encrypted data is 32 bytes (after decoding the Base64). "heidi" is less than a block size so will pad to 16-bytes. That leaves a mystery 16-bytes.
Upvotes: 4