为什么我没有把sha256做好
Why am I not getting the sha256 right?
我正在使用crypto++库进行一些练习。我期望得到与从shell调用的sha256sum工具相同的输出。
// typedef unsigned char byte;
byte out[CryptoPP::SHA256::DIGESTSIZE];
byte in=65; // 'A'
CryptoPP::SHA256().CalculateDigest(out, &in, 1);
for(int i=0; i < CryptoPP::SHA256::DIGESTSIZE; i++)
std::cout << std::hex << (int)out[i];
std::cout << std::endl;
559aead08264d5795d399718cdd5bd49572e84fe55590eef31a88a08fdffd
$ echo A | sha256sum
06f961b802bc46ee168555f066d28f4f0e9afdf3f88174c1ee6f9de004fc30a0
为什么两者不相等?
echo
会添加一行换行符,因此您可以比较不同字符串的哈希值。改为使用printf
:
$ printf 'A' | sha256sum
559aead08264d5795d3909718cdd05abd49572e84fe55590eef31a88a08fdffd -
$ printf 'An' | sha256sum
06f961b802bc46ee168555f066d28f4f0e9afdf3f88174c1ee6f9de004fc30a0 -
在命令行中,您正在对A
+换行进行校验和。
如果您的unix版本支持它,请使用echo -n
进行回显,而不添加换行符;
$ echo -n A | sha256sum
559aead08264d5795d3909718cdd05abd49572e84fe55590eef31a88a08fdffd -
相关文章:
- 如何在 c++ 中生成十六进制二进制数据的 sha256 哈希?
- C++:有效地将Sha256摘要放入OpenSSL Bignum?
- C++openssl SHA256运行速度比JDK SHA256实现慢
- 加密++库中的SHA256
- 如何使用 AES 和 sha256 哈希作为密钥加密++进行加密
- C++项目需要什么才能使用证书 (RSA-SHA256) 对文件进行签名
- OPENSSL 将二进制字节转换为 SHA256 C++
- 如何通过 CMake 使用他们的 SHA256 哈希下载提升?
- SHA256 HMAC使用OpenSL 1.1不编译
- 如何使用openssl/sha.h对文本文件进行SHA256哈希处理
- CMake检查下载文件的哈希值(MD5/SHA256)
- 如何使用OpenSSL的SHA256函数
- 将Botan SHA256输出转换为base64,以匹配.NET SHA256 MALAGENG().computeHa
- C++在哪里可以获得sha256 openssl的代码版本
- OpenSSL SHA256错误的结果
- 这个sha256函数出了什么问题
- C++中的SHA256哈希计算
- 无法使用 RSA-Sha256 进行签名.WatchData CSP 不是 CNG(加密 API:下一代)提供程序吗?
- 持久化sha256哈希对象
- 为什么我没有把sha256做好