Saturday, 15 August 2015

c++ - Code to decrypt the encrypted SHA256 code into string in crypto++ -



c++ - Code to decrypt the encrypted SHA256 code into string in crypto++ -

i using crypto++ encrypt , decrypt string .the code shown below. code encrypts username , password .but don't know how decrypt 1 1 time again string. code decrypt encrypted sha256 code string. can 1 help me.

#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 => " << output << std::endl; homecoming 0; }

this code not performing encryption, commentors pointed out, hashing. central difference hashing, design, not reversible cheaply. of import in password applications because explicitly not want store user's passwords in accessible form, check against them.

so, in short words: cannot "decrypt" hash.

when want check supplied password correctness, hash 1 time again in code , compare hash against hash of original password.

c++ crypto++

No comments:

Post a Comment