将 uint8_t 数组转换为 NSString
如何将 uint8_t
数组(请参阅下面的 decryptedBuffer
)影响到 NSString
?
uint8_t *decryptedBuffer;
NSString *cle2=[NSString stringWithUTF8String:decryptedBuffer];
NSString *str2=[player.name AES256DecryptWithKey:cle2];
NSLog(str2);
free(plainBuffer);
free(cipherBuffer);
free(decryptedBuffer);
How can I affect a uint8_t
array (see decryptedBuffer
below) to an NSString
?
uint8_t *decryptedBuffer;
NSString *cle2=[NSString stringWithUTF8String:decryptedBuffer];
NSString *str2=[player.name AES256DecryptWithKey:cle2];
NSLog(str2);
free(plainBuffer);
free(cipherBuffer);
free(decryptedBuffer);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
uint8_t *
只是一个与char *
兼容的字节字符串,因此您应该能够将转换后的指针传递给stringWithUTF8String
,假设解密后的字符串是 UTF-8 并且以 NULL 结尾:如果数据不是 NULL 结尾,您可以使用以下命令:
uint8_t *
is just a byte string which is compatible withchar *
, so you should just be able to pass the casted pointer tostringWithUTF8String
, assuming the decrypted string is UTF-8 and it is NULL terminated:If the data is not NULL terminated, you can use this:
cryptodBuffer 是一个 int (uint8_t),NSString stringWithUTF8String 仅适用于字符串,不适用于整数。我想我找到了你需要的东西: http://lists.apple .com/archives/cocoa-dev/2004/Apr/msg01437.html
那个人使用了这个语法:
所以你应该这样做:
decryptedBuffer is an int (uint8_t), NSString stringWithUTF8String only works on strings, not ints. I think I found what you need: http://lists.apple.com/archives/cocoa-dev/2004/Apr/msg01437.html
That person used this syntax:
So you should do this: