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;
|
||||
}
|
||||
|
|
|
@ -28,15 +28,18 @@
|
|||
* @author manzerbredes
|
||||
*
|
||||
* This class provide AES encrypt and decrypt.
|
||||
* Key used is 32 bytes key (256 bits).
|
||||
*
|
||||
* \bug Find another solution for managing padding.
|
||||
*/
|
||||
|
||||
class AESCrypt : public AbstractSKA {
|
||||
|
||||
|
||||
public:
|
||||
//Constructor
|
||||
AESCrypt();
|
||||
|
||||
//Destructor
|
||||
~AESCrypt();
|
||||
|
||||
|
||||
|
@ -48,14 +51,32 @@ class AESCrypt : public AbstractSKA {
|
|||
*
|
||||
* @return string : correspond to crypted data
|
||||
*
|
||||
* Run encryptRoutine with byte* key or string key
|
||||
* Run encryptRoutine with byte* key or string key.
|
||||
* Allow you to choose between string key or byte key.
|
||||
*
|
||||
*/
|
||||
std::string encrypt(std::string key, std::string data);
|
||||
std::string encrypt(byte* key, std::string data);
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Decrypt data from AES algorithm.
|
||||
*
|
||||
* @param key : key used to encrypt data
|
||||
* @param data : contain data to decrypt from AES encrypt.
|
||||
*
|
||||
* @return string : correspond to decrypted data
|
||||
*
|
||||
* Decrypt data, and return them into a string.
|
||||
*
|
||||
*/
|
||||
std::string decrypt(std::string key, std::string data);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Encrypt data with AES algorithm.
|
||||
*
|
||||
* @param key : key used to encrypt data
|
||||
|
@ -70,23 +91,8 @@ class AESCrypt : public AbstractSKA {
|
|||
std::string encryptRoutine(std::string data, byte* digest, int size);
|
||||
|
||||
|
||||
//Attributes:
|
||||
|
||||
/**
|
||||
* @brief Decrypt data from AES algorithm.
|
||||
*
|
||||
* @param key : key used to encrypt data
|
||||
* @param data : contain data to decrypt from AES encrypt.
|
||||
*
|
||||
* @return string : correspond to decrypted data
|
||||
*
|
||||
* Decrypt data, and return them into a string.
|
||||
*
|
||||
*/
|
||||
virtual std::string decrypt(std::string key, std::string data);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
HASHCrypt hash; ///< hash instance to generate SHA-256 hash code.
|
||||
|
||||
|
||||
|
|
29
main.cpp
29
main.cpp
|
@ -48,35 +48,6 @@ int main(int argc, char *argv[]){
|
|||
FileManParser parser(xml);
|
||||
|
||||
|
||||
|
||||
//std::cout << std::endl << parser.getData() << std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*std::string chaine="It's work !";
|
||||
std::string key="loic";
|
||||
AESCrypt aes;
|
||||
|
||||
|
||||
FileManIOFile fichier = FileManIOFile("Doxygen/bob.bin");
|
||||
|
||||
fichier.write(key, chaine);
|
||||
|
||||
fichier.read(key);
|
||||
|
||||
if(fichier.isReadable())
|
||||
std::cout << fichier.getData();
|
||||
|
||||
fichier.write(chaine+" YES");
|
||||
|
||||
fichier.read(key);
|
||||
|
||||
if(fichier.isReadable())
|
||||
std::cout << fichier.getData();*/
|
||||
|
||||
FileManContainer container= parser.getContainer();
|
||||
std::vector<Website> websites= container.getWebsites();
|
||||
std::cout << websites.at(0).getId();
|
||||
|
|
Loading…
Add table
Reference in a new issue