[英]Converting a uint8_t array to an 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);
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];
decryptedBuffer 是一個 int (uint8_t),NSString stringWithUTF8String 僅適用於字符串,不適用於 int。 我想我找到了你需要的東西: http://lists.apple.com/archives/cocoa-dev/2004/Apr/msg01437.html
那個人使用了這種語法:
NSString *theDigitsIWant = [[NSNumber numberWithInt:x] stringValue];
所以你應該這樣做:
NSString *cle2 = [[NSNumber numberWithInt:decryptedBuffer] stringValue];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.