以下のハッシュデータを印刷したいと思います。どうすればいいですか?
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??
16進形式の指定子は単一の整数値を期待していますが、代わりにの配列を提供していますchar
。必要なのは、char
値を16進値として個別に出力することです。
printf("hashedChars: ");
for (int i = 0; i < 32; i++) {
printf("%x", hashedChars[i]);
}
printf("\n");
cout
C ++を使用しているので、代わりに使用することを検討する必要がありますprintf
(C++ではより慣用的です。
cout << "hashedChars: ";
for (int i = 0; i < 32; i++) {
cout << hex << hashedChars[i];
}
cout << endl;
C++では
#include <iostream>
#include <iomanip>
unsigned char buf0[] = {4, 85, 250, 206};
for (int i = 0;i < sizeof buf0 / sizeof buf0[0]; i++) {
std::cout << std::setfill('0')
<< std::setw(2)
<< std::uppercase
<< std::hex << (0xFF & buf0[i]) << " ";
}