首页 > 解决方案 > std::vector 的 sha1 哈希使用加密++

问题描述

我收集了该类型的向量,std::vector<uint8_t>我需要为每个单独的向量存储一个散列值。我想为此使用crypto++。但我不确定这是否可能。据我所知,如果我把它做成std::vector<byte>. 但是,我看到的示例也提供了 a 中的哈希值std::vector<byte>。那么我想用crypto++做些什么还是我需要寻找另一个库?如果是,你能提供一个例子吗?

编辑: 带有字节指针的示例(https://www.cryptopp.com/wiki/User_guide:_cryptlib.h):

byte const* pbData1 = ...;
byte const* pbData2 = ...
unsigned int nData1Len = ...;
unsigned int nData2Len = ...;
byte abDigest[SHA::DIGESTSIZE];

SHA hash;
hash.Update(pbData1, nData1Len);
hash.Update(pbData2, nData2Len);
hash.Final(abDigest);

// abDigest now contains the hash of pbData1 and pbData2;
// the object 'hash' can now be reused to calculate another digest

...

SHA hash;
hash.Update(pbData1, nData1Len);
hash.Update(pbData2, nData2Len);
if (!hash.Verify(abDigest))
    throw "abDigest does not contain the right hash";

标签: c++crypto++

解决方案


推荐阅读