如何将 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);
最佳答案
uint8_t *
只是一个与 char *
兼容的字节字符串,因此您应该能够将转换后的指针传递给 stringWithUTF8String
,假设解密后的字符串是 UTF-8 并且以 NULL 结尾:
NSString *s = [NSString stringWithUTF8String:(char *)decryptedBuffer];
如果数据不是以NULL结尾,你可以这样使用:
NSString *s = [[[NSString alloc] initWithBytes:decryptedBuffer
length:length_of_buffer
encoding:NSUTF8StringEncoding] autorelease];
关于iphone - 将 uint8_t 数组转换为 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6579458/