使用crypto++的HMAC解密植物文本



我在使用crypto++库的HMAC时遇到问题

我已经使用这个链接来制作加密消息crypto++-HMAC,它工作正常

AutoSeededRandomPool prng;
SecByteBlock key(16);
prng.GenerateBlock(key, key.size());
string plain = "HMAC Test";
string mac, encoded;
// Pretty print key
encoded.clear();
StringSource ss1(key, key.size(), true,
new HexEncoder(
new StringSink(encoded)
) // HexEncoder
); // StringSource
cout << "key: " << encoded << endl;
cout << "plain text: " << plain << endl;
try
{
HMAC< SHA256 > hmac(key, key.size());
StringSource ss2(plain, true, 
new HashFilter(hmac,
new StringSink(mac)
) // HashFilter      
); // StringSource
}
catch(const CryptoPP::Exception& e)
{
cerr << e.what() << endl;
exit(1);
}
// Pretty print
encoded.clear();
StringSource ss3(mac, true,
new HexEncoder(
new StringSink(encoded)
) // HexEncoder
); // StringSource
cout << "hmac: " << encoded << endl;

现在在另一边,我想解密这个消息并获得真正的纯文本但我还没有得到任何结果。我已经检查了这个链接解码的步骤,但它对我没有帮助。我不知道我应该在哪里使用Key?

请指导我找到解决方案

我知道HMAC不是一种加密算法,它是一种编码算法。

其他人可以使用HMAC看到我们的消息,但他们不能给我们未经验证的消息。

并且所有的消息字节都可以被编码用于发送,在接收器部分,我们用我们的密钥解码并检查消息的权限,根据我们使用的哈希函数(MD5、SHA1、SHA256(,消息的编码部分具有固定的大小

最新更新