From 12512398bd3cfc4706c4d1b3275919338e8a117b Mon Sep 17 00:00:00 2001
From: manzerbredes <loic.guegan_secondary@yahoo.fr>
Date: Fri, 13 Mar 2015 15:21:46 +0400
Subject: [PATCH] Check all CryptClass

---
 CryptClass/AESCrypt.cpp | 15 ++++++++------
 CryptClass/AESCrypt.hpp | 44 +++++++++++++++++++++++------------------
 main.cpp                | 29 ---------------------------
 3 files changed, 34 insertions(+), 54 deletions(-)

diff --git a/CryptClass/AESCrypt.cpp b/CryptClass/AESCrypt.cpp
index 4f7309e..d3ea949 100644
--- a/CryptClass/AESCrypt.cpp
+++ b/CryptClass/AESCrypt.cpp
@@ -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;
 }
diff --git a/CryptClass/AESCrypt.hpp b/CryptClass/AESCrypt.hpp
index 5e16672..c4d75aa 100644
--- a/CryptClass/AESCrypt.hpp
+++ b/CryptClass/AESCrypt.hpp
@@ -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.
 
 
diff --git a/main.cpp b/main.cpp
index bae168f..2cbc9ef 100644
--- a/main.cpp
+++ b/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();