summaryrefslogtreecommitdiff
path: root/CryptClass/HASHCrypt.cpp
blob: ec25bf6860f83292d987681cf8afaf12d38ed27a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "HASHCrypt.hpp"



//Constructeur
HASHCrypt::HASHCrypt(std::string chain){
    this->MD5_32=this->initMD5_32(chain);    //Initialisation MD5 sur 32bits
    this->MD5_128=this->initMD5_128(chain);  //Initialisation MD5 sur 128bits
}


//Destructeur
HASHCrypt::~HASHCrypt(){
}



//Retourne la somme de controle MD5 sur 32 bits
std::string HASHCrypt::initMD5_32(std::string chain){

    //Calcule de la somme de controle MD5 dans un type byte à partir du paramètre chain
    CryptoPP::Weak1::MD5 hash;
    byte digest[ CryptoPP::Weak1::MD5::DIGESTSIZE ];
    hash.CalculateDigest( digest, (byte*) chain.c_str(), 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
std::string HASHCrypt::initMD5_128(std::string chain){

    //Calcule de la somme de controle MD5 dans un type byte à partir du paramètre chain
    CryptoPP::Weak1::MD5 hash;
    byte digest[ CryptoPP::Weak1::MD5::DIGESTSIZE * 4 ];
    hash.CalculateDigest( digest, (byte*) chain.c_str(), 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;
}


//Getter MD5_32
std::string HASHCrypt::getMD5_32(){
    return this->MD5_32;
}

//Getter MD5_128
std::string HASHCrypt::getMD5_128(){
    return this->MD5_128;
}