如何将加密数据转换为字符串
我已经使用 任何用于 AES 加密的可可源代码中发布的代码对 NSData 进行了加密解密?(由 Rob Keniger 回答)。现在我需要检查加密是否正确。为此,我使用代码将加密的 NSData 转换为 NSString,
NSString *string=[[NSString alloc]initWithBytes:[cipherData bytes] length:[cipherData length] encoding:NSUTF8StringEncoding];
但是当 NSLog 编辑时,它显示 (null)。我的疑问是 crypt() 函数是否以不同的编码而不是 NSUTF8StringEncoding 加密数据?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
总的来说,NSData不能直接转NSString,我有个建议,你可以把这个NSData转Base64 NSString,如果你不想转回来,那就用Base64从NSString转NSData,找到一个“GTMBase64.h” ,这将帮助您
编码
解码
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
Decode