开发者

how make Hexa must be 2 Digit on NSData

I try use encrypt aes on iphone and success, but the result i want on nsdata must be 2 digit hexa, i try to print the result of cipher whit this code :

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] : 44

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜