hash functions
This commit is contained in:
@ -252,6 +252,22 @@ namespace Utilities {
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string createHashSha256(const std::string& str){
|
||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||
|
||||
SHA512_CTX sha256;
|
||||
SHA512_Init(&sha256);
|
||||
SHA512_Update(&sha256, str.c_str(), str.size());
|
||||
SHA512_Final(hash, &sha256);
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
for(int i = 0; i < SHA256_DIGEST_LENGTH; i++){
|
||||
ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>( hash[i] );
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*
|
||||
* Generates a salt using Mersenne Twister
|
||||
*/
|
||||
@ -320,8 +336,15 @@ namespace Utilities {
|
||||
/*
|
||||
* Generates a hash based on a combination of 2 random salts
|
||||
*/
|
||||
std::string generateLoginKeyValue() {
|
||||
return hashPassword(generateSalt(), generateSalt());
|
||||
std::string generateRandomHashValueSHA512() {
|
||||
return createHashSha512(generateSalt() + generateSalt());
|
||||
}
|
||||
|
||||
/*
|
||||
* Generates a hash based on a combination of 2 random salts
|
||||
*/
|
||||
std::string generateRandomHashValueSHA256() {
|
||||
return createHashSha256(generateSalt() + generateSalt());
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user