我想打印以下散列数据。我该怎么办?
unsigned char hashedChars[32];
SHA256((const unsigned char*)data.c_str(),
data.length(),
hashedChars);
printf("hashedChars: %X\n", hashedChars); // doesn't seem to work??
我想打印以下散列数据。我该怎么办?
unsigned char hashedChars[32];
SHA256((const unsigned char*)data.c_str(),
data.length(),
hashedChars);
printf("hashedChars: %X\n", hashedChars); // doesn't seem to work??
十六进制格式说明符期望一个整数值,但您提供的是一个数组 char
。你需要做的就是打印出来 char
值单独作为十六进制值。
printf("hashedChars: ");
for (int i = 0; i < 32; i++) {
printf("%x", hashedChars[i];
}
printf("\n");
因为你正在使用C ++,你应该考虑使用 cout
代替 printf
(对于C ++来说,它更具惯用性。
cout << "hashedChars: ";
for (int i = 0; i < 32; i++) {
cout << hex << hashedChars[i];
}
cout << endl;
十六进制格式说明符期望一个整数值,但您提供的是一个数组 char
。你需要做的就是打印出来 char
值单独作为十六进制值。
printf("hashedChars: ");
for (int i = 0; i < 32; i++) {
printf("%x", hashedChars[i];
}
printf("\n");
因为你正在使用C ++,你应该考虑使用 cout
代替 printf
(对于C ++来说,它更具惯用性。
cout << "hashedChars: ";
for (int i = 0; i < 32; i++) {
cout << hex << hashedChars[i];
}
cout << endl;