Création du projet !
This commit is contained in:
commit
1c6f11fdd8
5 changed files with 120 additions and 0 deletions
0
CryptClass/AESCrypt.cpp
Normal file
0
CryptClass/AESCrypt.cpp
Normal file
0
CryptClass/AESCrypt.hpp
Normal file
0
CryptClass/AESCrypt.hpp
Normal file
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;
|
||||
}
|
35
CryptClass/HASHCrypt.hpp
Normal file
35
CryptClass/HASHCrypt.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
//----- Includes std -----
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
//----- Includes crypto++ -----
|
||||
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
|
||||
|
||||
//Pour le calcule de la somme de controle MD5
|
||||
#include "crypto++/md5.h"
|
||||
//Pour la convertion en hexadécimal et vice-versa
|
||||
#include "crypto++/hex.h"
|
||||
|
||||
|
||||
/*----- Description -----
|
||||
Classe executant divers fonctions de hashage sur
|
||||
un attribut chain en utilisant la bibiothèque crypto++
|
||||
*/
|
||||
|
||||
class HASHCrypt{
|
||||
|
||||
public:
|
||||
HASHCrypt(std::string chain);
|
||||
~HASHCrypt();
|
||||
|
||||
std::string getMD5_32(); //Calcule de la somme de controle MD5 sur 32bit
|
||||
std::string getMD5_128(); //Calcule de la somme de controle MD5 sur 128bit
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::string chain; //Attribut paramètre des fonctions de hashage
|
||||
|
||||
|
||||
};
|
33
main.cpp
Normal file
33
main.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
//----- Includes std -----
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
//----- Includes personnal Class -----
|
||||
#include "CryptClass/HASHCrypt.hpp"
|
||||
|
||||
//----- Prototype -----
|
||||
void aff(std::string chaine);
|
||||
|
||||
|
||||
|
||||
|
||||
//----- Program Start -----
|
||||
int main(){
|
||||
|
||||
HASHCrypt hash= HASHCrypt("Chaine");
|
||||
|
||||
aff(hash.getMD5_32());
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//---- Functions -----
|
||||
|
||||
void aff(std::string chaine){
|
||||
std::cout << chaine;
|
||||
}
|
Loading…
Add table
Reference in a new issue