Création du projet !
This commit is contained in:
commit
1c6f11fdd8
5 changed files with 120 additions and 0 deletions
52
CryptClass/HASHCrypt.cpp
Normal file
52
CryptClass/HASHCrypt.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "HASHCrypt.hpp"
|
||||
|
||||
|
||||
|
||||
//Constructeur
|
||||
HASHCrypt::HASHCrypt(std::string chain){
|
||||
this->chain=chain; //Initialisation de l'attribut chain
|
||||
}
|
||||
|
||||
//Destructeur
|
||||
HASHCrypt::~HASHCrypt(){
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Retourne la somme de controle MD5 sur 32 bits de l'attribut chain
|
||||
std::string HASHCrypt::getMD5_32(){
|
||||
|
||||
//Calcule de la somme de controle MD5 dans un type byte à partir de l'attribut chain
|
||||
CryptoPP::Weak1::MD5 hash;
|
||||
byte digest[ CryptoPP::Weak1::MD5::DIGESTSIZE ];
|
||||
hash.CalculateDigest( digest, (byte*) this->chain.c_str(), this->chain.length() );
|
||||
|
||||
//Convertion du hash en std::string
|
||||
CryptoPP::HexEncoder encoder;
|
||||
std::string output;
|
||||
encoder.Attach( new CryptoPP::StringSink( output ) );
|
||||
encoder.Put( digest, sizeof(digest) );
|
||||
encoder.MessageEnd();
|
||||
|
||||
//Retourne la sortie de la convertion
|
||||
return output;
|
||||
}
|
||||
|
||||
//Retourne la somme de controle MD5 sur 128 bits de l'attribut chain
|
||||
std::string HASHCrypt::getMD5_128(){
|
||||
|
||||
//Calcule de la somme de controle MD5 dans un type byte à partir de l'attribut chain
|
||||
CryptoPP::Weak1::MD5 hash;
|
||||
byte digest[ CryptoPP::Weak1::MD5::DIGESTSIZE * 4 ];
|
||||
hash.CalculateDigest( digest, (byte*) this->chain.c_str(), this->chain.length() );
|
||||
|
||||
//Convertion du hash en std::string
|
||||
CryptoPP::HexEncoder encoder;
|
||||
std::string output;
|
||||
encoder.Attach( new CryptoPP::StringSink( output ) );
|
||||
encoder.Put( digest, sizeof(digest) );
|
||||
encoder.MessageEnd();
|
||||
|
||||
//Retourne la sortie de la convertion
|
||||
return output;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue