[Metalab] Secure password hashing in c++ using cryptopp

Amir amir at viel-zu.org
Wed Sep 12 13:09:39 CEST 2018


ich hab mir eine passwort hashing funktion gezimmert und hab aber 
zweifel ob sie sicher ist. was denkt ihr?

#include <cryptopp/hex.h>
#include <cryptopp/sha.h>
#include <cryptopp/base64.h>
#include <random>

using std::string;

std::<string,string> hash_password(const string password)
{
   std::mt19937 rng;
   rng.seed(std::random_device()());
   std::uniform_real_distribution<std::mt19937::result_type> dist(0,1);

   string salt = std::to_string(dist(rng));
   CryptoPP::SHA256 hash;
   byte digest[CryptoPP::SHA256::DIGESTSIZE];
   std::string output;

   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();

   return {output, salt};
}




More information about the Metalab mailing list