gpt4 book ai didi

c++ - 使用 CryptoPP::HexDecoder( )

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:21:24 25 4
gpt4 key购买 nike

我是第一次玩 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(source, true,
new CryptoPP::HashFilter(sha1,
new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash))));

不要使用匿名声明。命名你的变量。改用这个:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com