I am playing with Cryptopp for ther first time and I found an example to encode to Hex...All is well. Now I want to decode std::string produced into original string but all I get is empty 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))));
Don't use anonymous declarations. Name your variables. Use this instead:
CryptoPP::StringSource ss(source, true,
new CryptoPP::HashFilter(sha1,
new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash)
)));
Do it for all of them.
Also see CryptoPP HexDecoder output empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With