[英]C++ hashing algorithm
I have the following algoritm (based on SHA-1 hash function implementation). 我有以下算法(基于SHA-1哈希函数实现)。 It produces the hash of "abc". 产生“ abc”的哈希。 The result is the unsigned char*
digest. 结果是未签名的char*
摘要。
#define BYTES "abce"
SHA1* sha1 = new SHA1();
sha1->addBytes( BYTES, strlen( BYTES ) );
unsigned char* digest = sha1->getDigest();
I would like to rehash the result digest. 我想重新整理结果摘要。 I m doing this in the following way but does not work. 我正在以以下方式执行此操作,但不起作用。 Is char* S
defined something different from #define BYTES "abce"
? 是char* S
定义的与#define BYTES "abce"
吗?
char* S = reinterpret_cast<char*>(digest);
sha1 = new SHA1();
sha1->addBytes( S, strlen( S ) );
unsigned char* digest1 = sha1->getDigest();
Do not ever use strlen
on anything but a C-style string. 除C风格的字符串外,不要在其他任何东西上使用strlen
。
sha1->addBytes( S, strlen( S ) );
That makes no sense. 这是没有意义的。 You probably want 20, the size of a SHA digest. 您可能需要20个SHA摘要的大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.