Check all CryptClass
This commit is contained in:
parent
802410f7a3
commit
12512398bd
3 changed files with 34 additions and 54 deletions
|
@ -8,12 +8,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
//----- class -----
|
||||
#include "AESCrypt.hpp"
|
||||
|
||||
|
||||
|
||||
|
||||
//Constructor
|
||||
AESCrypt::AESCrypt(){
|
||||
this->hash=HASHCrypt(); //Init hash attribute
|
||||
|
@ -26,7 +26,6 @@ AESCrypt::~AESCrypt(){
|
|||
|
||||
|
||||
|
||||
|
||||
//Encrypt string with string key
|
||||
std::string AESCrypt::encrypt(std::string key, std::string data){
|
||||
|
||||
|
@ -38,11 +37,15 @@ std::string AESCrypt::encrypt(std::string key, std::string data){
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Encrypt string with byte* key
|
||||
std::string AESCrypt::encrypt(byte* key, std::string data){
|
||||
return encryptRoutine(data, key, 32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//The encryptRoutine
|
||||
std::string AESCrypt::encryptRoutine(std::string data, byte* digest, int size){
|
||||
//Contain data encrypted
|
||||
|
@ -78,11 +81,10 @@ std::string AESCrypt::encryptRoutine(std::string data, byte* digest, int size){
|
|||
|
||||
|
||||
|
||||
|
||||
//Decrypt string
|
||||
std::string AESCrypt::decrypt(std::string key, std::string data){
|
||||
|
||||
|
||||
//Get SHA-256
|
||||
byte digest[32];
|
||||
hash.getSHA_256(key, digest, (int)sizeof(digest));
|
||||
|
||||
|
@ -111,13 +113,14 @@ std::string AESCrypt::decrypt(std::string key, std::string data){
|
|||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
//Remove ZEROS padding
|
||||
int i=0;
|
||||
for(i=0;i<cipher.length();i++){
|
||||
if(cipher[i]=='\0')
|
||||
break;
|
||||
}
|
||||
cipher.erase(i,cipher.length()-1);
|
||||
cipher.erase(i,cipher.length()-1); //Erase ZEROS
|
||||
|
||||
//return decrypted data
|
||||
return cipher;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue