我正在使用crypto ++来加密和解密字符串。代码如下所示。 该代码加密用户名和密码。但我不知道如何将其解密为一个字符串。将加密的SHA256代码解密为字符串的代码是什么? 任何人都可以帮助我。将加密的SHA256代码解密为crypto ++中的字符串的代码
#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
#include <cryptopp/base64.h>
#include <iostream>
#include <string>
int main()
{
CryptoPP::SHA256 hash;
byte digest[CryptoPP::SHA256::DIGESTSIZE];
std::string username, password, salt, output;
std::cout << "Enter username: ";
std::getline(std::cin,username);
std::cout << std::endl << "Enter password: ";
std::getline(std::cin,password);
salt = username + password;
hash.CalculateDigest(digest,(const byte *)salt.c_str(),salt.size());
CryptoPP::HexEncoder encoder;
CryptoPP::StringSink *SS = new CryptoPP::StringSink(output);
encoder.Attach(SS);
encoder.Put(digest,sizeof(digest));
encoder.MessageEnd();
std::cout << "The username/password salted hash is => " << output << std::endl;
return 0;
}
请阅读http://en.wikipedia.org/wiki/Cryptographic_hash_function - 你所要求的是不可行*通过设计*。 – 2013-02-20 17:06:05
另请参阅[pigeonhole原理](https://en.wikipedia.org/wiki/Pigeonhole_principle) – Praetorian 2013-02-20 17:09:52