[英]padding with PKCS7 [C]
I want to do padding with PKCS7 : 我想用PKCS7进行填充:
char *test1 = "azertyuiopqsdfgh";
char *test2 = malloc(32*sizeof(char));
memcpy(test2, test1, strlen(test1));
char pad = (char)(32-strlen(test1));
printf("pad = %d\n", pad);
for(int i = strlen(test1) ; i < 32 ; i++) {
test2[i] = pad;
}
for (int i = 0 ; i < 32 ; i++)
printf("%x ", test2[i]);
printf("\n");
I obtain : 我得到:
pad = 16
61 7a 65 72 74 79 75 69 6f 70 71 73 64 66 67 68 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10
But i want : 但我想要 :
pad = 16
61 7a 65 72 74 79 75 69 6f 70 71 73 64 66 67 68 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16
How can i modify my code ? 我该如何修改我的代码?
Thanks in advance. 提前致谢。
With 用
printf("%x ", test2[i]);
You are printing in hexadecimal ( %x ) whereas with 您使用十六进制( %x )打印,而使用
printf("pad = %d\n", pad);` you are printing in decimal (%d).
And (decimal) 16 => (hexa) 10 , So you are displaying the right thing. 和(十进制)16 =>(六)10 ,所以您正在显示正确的东西。
You could probably play a bit with your printing to display 16 instead of 10 but I don't think this is what you are searching for. 您可能会在打印中显示16而不是10,但是我认为这不是您要搜索的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.