0
votes

I have encrypted NSData using the code posted in Any cocoa source code for AES encryption decryption? (Answered by Rob Keniger). Now I need to check the encryption is correct or not. For that I converted encrypted NSData to NSString, using the code

NSString *string=[[NSString alloc]initWithBytes:[cipherData bytes] length:[cipherData length] encoding:NSUTF8StringEncoding]; 

but when NSLog ed, it shows (null). My doubt is does the crypt() function encrypt data in different encoding rather than NSUTF8StringEncoding?

1

1 Answers

1
votes

Overall,NSData can't directly transfer to NSString,I have a suggestion,you can make this NSData to Base64 NSString,and if you wan't to covert back,then use Base64 from NSString to NSData,find A "GTMBase64.h",that will help you

Encode

NSString *imageStr = [GTMBase64 stringByEncodingData:imageData];

Decode

NSData *imageData = [GTMBase64 decodeString:imageStr];