Using CryptoPP::HexDecoder( )
Using CryptoPP::HexDecoder( )
我第一次玩Cryptopp,我找到了一个编码为Hex的例子。。。一切都很好。现在,我想将生成的std::字符串解码为原始字符串,但得到的只是空字符串。
#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输出为空。
相关文章:
- "using namespace std;"在C++的作用是什么?
- vector<vector<double>> to mxArray using memcpy
- Using C++ CryptAPI:CNG Create CSR
- STLPort using C++11
- 函数中的 c++ using 语句,后跟函数名称(对于 ADL?
- Using getchar_unlocked()
- 类作用域的类型别名"using":[何时]方法中的用法可以先于类型别名?
- 嵌套命名空间的"using"指令,但需要命名内部命名空间
- 为什么"using System;"不被视为不良做法?
- 为什么我需要做'using namespace std'而不是"使用 std::cout"?
- 'using namespace'实现细节的便捷方法(仅标头库)?
- C++中"typedef"、"using"、"namespace"和"using namespace"有什么区别?
- 在"template"和函数声明之间使用:template<typename trait> using tr = base_trait<trait> void fn(tr::t
- 如何区分C++中的"using declaration"和"using directive"?
- C++ "using tcp=x"到"namespace tcp=x"有什么区别
- 如何为流输出运算符提供重载<<模板'using'类型别名?
- Using PrimitiveBatch::DrawIndexed with ID3D11DeviceContext::
- 如何创建一个 while 循环,继续循环,直到在C++中输入'using streams'键?
- 是否可以使用 using 将基类中的公共成员重新声明为派生类中的私有成员?
- Using CryptoPP::HexDecoder( )