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 AES256Decrypt开发者_如何学GoWithKey:cle2];
NSLog(str2);
free(plainBuffer);
free(cipherBuffer);
free(decryptedBuffer);
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];
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];
精彩评论