Implement hashing using OpenSSL

This commit is contained in:
Tina_Azure 2023-04-19 02:06:19 +02:00
parent 795048018c
commit a0be80825f
1 changed files with 29 additions and 1 deletions

View File

@ -2,17 +2,22 @@
#include <list>
#include <map>
#include <iostream>
#include <random>
#include <fstream>
#include <locale>
#include <codecvt>
#include <regex>
#include <vector>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <stdexcept>
#include <pqxx/pqxx>
#include "crow.h"
#include "cpp/opportunisticsecuresmtpclient.hpp"
#include "cpp/plaintextmessage.hpp"
#include "cpp/htmlmessage.hpp"
#include <stdexcept>
#include <openssl/sha.h>
using namespace jed_utils::cpp;
@ -214,4 +219,27 @@ namespace Utilities {
}
return 0;
}
std::string createHashSha512(const std::string str){
unsigned char hash[SHA512_DIGEST_LENGTH];
SHA512_CTX sha512;
SHA512_Init(&sha512);
SHA512_Update(&sha512, str.c_str(), str.size());
SHA512_Final(hash, &sha512);
std::stringstream ss;
for(int i = 0; i < SHA512_DIGEST_LENGTH; i++){
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>( hash[i] );
}
return ss.str();
}
/*
* Hashes a given password with a given salt
*/
std::string hashPassword(std::string pwsalt, std::string password) {
return createHashSha512(pwsalt + password);
}
}