how make Hexa must be 2 Digit on NSData
unsigned char ciphertext[16];
....
...
...
...
for (int i=0; i<sizeof(ciphertext); i++) {
NSLog(@"ciphertext[%d] : %x ",i,ciphertext[i]);
}
The result is :
ciphertext[0] : 43
ciphertext[1] : d4 ciphertext[2] : a5 ciphertext[3] : ee ciphertext[4] : 24 ciphertext[5] : a5 ciphertext[6] : 31 ciphertext[7] : 62 ciphertext[8] : 1c ciphertext[9] : 99 ciphertext[10] : 88 ciphertext[11] : 29 ciphertext[12] : d6 ciphertext[13] : 97 ciphertext[14] : 7 <== this is problem, how make this to be 07 ? ciphertext[15] : 44Please help me to make this he开发者_StackOverflow社区xa to 2 digit ? Regards,
You can use:
NSLog(@"ciphertext[%d] : %02x ",i,ciphertext[i]);
See the IEEE printf specification for further options, that is referenced by the String Format Specifiers doc.
To store your char[]
to a NSData, you could do:
NSData *data = [NSData dataWithBytes:ciphertext length:16];
精彩评论