0

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?

Community
  • 1
  • 1
rakeshNS
  • 4,227
  • 4
  • 28
  • 42

1 Answers1

1

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];
carl
  • 318
  • 1
  • 9