我第一次玩 Cryptopp,我找到了一个编码为十六进制的例子......一切都很好。
现在我想将生成的 std::string 解码为原始字符串,但我得到的只是空字符串。
#include "stdafx.h"
#include "../cryptopp562/sha.h"
#include "../cryptopp562/filters.h"
#include "../cryptopp562/hex.h"
#include <iostream>
#include <string>
int main() {
CryptoPP::SHA1 sha1;
std::string source = "Panawara";
std::string hash = "";
std::string original= "" ;
CryptoPP::StringSource(source, true, new CryptoPP::HashFilter(sha1, new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash))));
std::cout << hash;
std::cout << "\n";
CryptoPP::StringSource (hash, new CryptoPP::HexDecoder(new CryptoPP::StringSink(original))); // the result is always empty String
std::cout << original;
std::cout << "\n";
system("pause");
}
最佳答案
不要使用匿名声明。命名变量。改用这个:
CryptoPP::StringSource ss(source, true,
new CryptoPP::HashFilter(sha1,
new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash)
)));
为他们所有人做这件事。
另见 CryptoPP HexDecoder output empty 。
关于c++ - 使用 CryptoPP::HexDecoder(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25744302/