将 uint8_t 数组转换为 NSString

发布于 2024-11-18 14:49:53 字数 349 浏览 1 评论 0原文

如何将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉生梦死 2024-11-25 14:49:53

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];

uint8_t * is just a byte string which is compatible with char *, so you should just be able to pass the casted pointer to stringWithUTF8String, assuming the decrypted string is UTF-8 and it is NULL terminated:

NSString *s = [NSString stringWithUTF8String:(char *)decryptedBuffer];

If the data is not NULL terminated, you can use this:

NSString *s = [[[NSString alloc] initWithBytes:decryptedBuffer
                                 length:length_of_buffer
                                 encoding:NSUTF8StringEncoding] autorelease];
旧人哭 2024-11-25 14:49:53

cryptodBuffer 是一个 int (uint8_t),NSString stringWithUTF8String 仅适用于字符串,不适用于整数。我想我找到了你需要的东西: http://lists.apple .com/archives/cocoa-dev/2004/Apr/msg01437.html

那个人使用了这个语法:

    NSString *theDigitsIWant = [[NSNumber numberWithInt:x] stringValue];

所以你应该这样做:

    NSString *cle2 = [[NSNumber numberWithInt:decryptedBuffer] stringValue];

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:

    NSString *theDigitsIWant = [[NSNumber numberWithInt:x] stringValue];

So you should do this:

    NSString *cle2 = [[NSNumber numberWithInt:decryptedBuffer] stringValue];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文