add editorconfig
pass on al file to reformat
This commit is contained in:
parent
34bc39b252
commit
0d28f4f519
27
.editorconfig
Normal file
27
.editorconfig
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# formatting rule for this project
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_size = 4
|
||||||
|
indent_style = space
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.cpp]
|
||||||
|
max_line_length = 119
|
||||||
|
|
||||||
|
# Ignored paths
|
||||||
|
[lib/**]
|
||||||
|
indent_size = unset
|
||||||
|
indent_style = unset
|
||||||
|
end_of_line = unset
|
||||||
|
insert_final_newline = unset
|
||||||
|
charset = unset
|
||||||
|
trim_trailing_whitespace = unset
|
||||||
|
|
||||||
|
# Makefiles always use tabs for indentation
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
18
aes.hpp
18
aes.hpp
@ -38,7 +38,7 @@ private:
|
|||||||
std::string generateNewFilename();
|
std::string generateNewFilename();
|
||||||
std::string getFilePath();
|
std::string getFilePath();
|
||||||
std::string extension = ".new";
|
std::string extension = ".new";
|
||||||
|
|
||||||
public:
|
public:
|
||||||
aes() {};
|
aes() {};
|
||||||
aes(std::string _filename);
|
aes(std::string _filename);
|
||||||
@ -68,7 +68,7 @@ aes::aes(std::string _filename) {
|
|||||||
|
|
||||||
aes& aes::clone(const aes& _e) {
|
aes& aes::clone(const aes& _e) {
|
||||||
filename = _e.filename;
|
filename = _e.filename;
|
||||||
|
|
||||||
setAesKey(_e.aesKey);
|
setAesKey(_e.aesKey);
|
||||||
setAesIV(_e.aesIV);
|
setAesIV(_e.aesIV);
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ int aes::readFile(unsigned char** file, const char* filename) {
|
|||||||
fprintf(stderr, "Failed to allocate memory\n");
|
fprintf(stderr, "Failed to allocate memory\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the file into the buffer
|
// Read the file into the buffer
|
||||||
size_t bytesRead = fread(*file, 1, fileLength, fd);
|
size_t bytesRead = fread(*file, 1, fileLength, fd);
|
||||||
|
|
||||||
@ -194,19 +194,19 @@ void aes::setAesKey(const unsigned char* _aesKey) {
|
|||||||
|
|
||||||
void aes::setAesIV(const unsigned char* _aesIV) {
|
void aes::setAesIV(const unsigned char* _aesIV) {
|
||||||
if(aesIV == NULL)
|
if(aesIV == NULL)
|
||||||
aesIV = (unsigned char*)malloc(AES_KEYLEN/8);
|
aesIV = (unsigned char*)malloc(AES_KEYLEN/8);
|
||||||
memcpy(aesIV , _aesIV, AES_KEYLEN/8);
|
memcpy(aesIV , _aesIV, AES_KEYLEN/8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned char* aes::getAesKey() {
|
unsigned char* aes::getAesKey() {
|
||||||
unsigned char* res = (unsigned char*)malloc(AES_KEYLEN/8);
|
unsigned char* res = (unsigned char*)malloc(AES_KEYLEN/8);
|
||||||
memcpy(res, aesKey, AES_KEYLEN/8);
|
memcpy(res, aesKey, AES_KEYLEN/8);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* aes::getAesIV() {
|
unsigned char* aes::getAesIV() {
|
||||||
unsigned char* res = (unsigned char*)malloc(AES_KEYLEN/8);
|
unsigned char* res = (unsigned char*)malloc(AES_KEYLEN/8);
|
||||||
memcpy(res, aesIV, AES_KEYLEN/8);
|
memcpy(res, aesIV, AES_KEYLEN/8);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ unsigned char* aes::getAesIV() {
|
|||||||
std::string aes::PrintAesKey() {
|
std::string aes::PrintAesKey() {
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
std::string res;
|
std::string res;
|
||||||
|
|
||||||
res = "aesKey : ";
|
res = "aesKey : ";
|
||||||
for (int i = 0; i < 32; i++) {
|
for (int i = 0; i < 32; i++) {
|
||||||
ss << std::hex;
|
ss << std::hex;
|
||||||
@ -226,7 +226,7 @@ std::string aes::PrintAesKey() {
|
|||||||
|
|
||||||
void aes::importKey(const char* filename) {
|
void aes::importKey(const char* filename) {
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
|
|
||||||
std::ifstream keyfile(filename, std::ifstream::binary);
|
std::ifstream keyfile(filename, std::ifstream::binary);
|
||||||
keyfile >> root;
|
keyfile >> root;
|
||||||
|
|
||||||
@ -256,4 +256,4 @@ void aes::clear_all() {
|
|||||||
free(aesKey);
|
free(aesKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -49,7 +49,7 @@ int crypt::aesEncrypt(const unsigned char *msg, size_t msgLen, unsigned char **e
|
|||||||
|
|
||||||
*encMsg = (unsigned char*)malloc(msgLen + AES_BLOCK_SIZE);
|
*encMsg = (unsigned char*)malloc(msgLen + AES_BLOCK_SIZE);
|
||||||
if(encMsg == NULL) return FAILURE;
|
if(encMsg == NULL) return FAILURE;
|
||||||
|
|
||||||
if(!EVP_EncryptInit_ex(aesEncryptCtx, EVP_aes_256_cbc(), NULL, aes::aesKey, aes::aesIV)) {
|
if(!EVP_EncryptInit_ex(aesEncryptCtx, EVP_aes_256_cbc(), NULL, aes::aesKey, aes::aesIV)) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
decrypt(std::string filename, unsigned char* aesKey=0, unsigned char* aesIV=0);
|
decrypt(std::string filename, unsigned char* aesKey=0, unsigned char* aesIV=0);
|
||||||
decrypt(const decrypt& a);
|
decrypt(const decrypt& a);
|
||||||
|
|
||||||
void init_all(bool initSuper=true);
|
void init_all(bool initSuper=true);
|
||||||
int aesDecrypt(unsigned char *encMsg, size_t encMsgLen, unsigned char** decMsg);
|
int aesDecrypt(unsigned char *encMsg, size_t encMsgLen, unsigned char** decMsg);
|
||||||
~decrypt();
|
~decrypt();
|
||||||
@ -55,7 +55,7 @@ int decrypt::aesDecrypt(unsigned char *encMsg, size_t encMsgLen, unsigned char *
|
|||||||
|
|
||||||
*decMsg = (unsigned char*)malloc(encMsgLen);
|
*decMsg = (unsigned char*)malloc(encMsgLen);
|
||||||
if(*decMsg == NULL) return FAILURE;
|
if(*decMsg == NULL) return FAILURE;
|
||||||
|
|
||||||
if(!EVP_DecryptInit_ex(aesDecryptCtx, EVP_aes_256_cbc(), NULL, aes::aesKey, aes::aesIV)) {
|
if(!EVP_DecryptInit_ex(aesDecryptCtx, EVP_aes_256_cbc(), NULL, aes::aesKey, aes::aesIV)) {
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
8
main.cpp
8
main.cpp
@ -18,11 +18,11 @@ int main(int argc, char* argv[]) {
|
|||||||
// readFile fait l'aloccation mémoire !!! pensé au free
|
// readFile fait l'aloccation mémoire !!! pensé au free
|
||||||
size_t fileLength = O->readFile(&file);
|
size_t fileLength = O->readFile(&file);
|
||||||
printf("%d bytes to be encrypted\n", (int)fileLength);
|
printf("%d bytes to be encrypted\n", (int)fileLength);
|
||||||
|
|
||||||
// Encrypt the file
|
// Encrypt the file
|
||||||
unsigned char *encryptedFile;
|
unsigned char *encryptedFile;
|
||||||
int encryptedFileLength;
|
int encryptedFileLength;
|
||||||
|
|
||||||
if((encryptedFileLength = (dynamic_cast<crypt*>(O))->aesEncrypt((const unsigned char*)file, fileLength, &encryptedFile) ) == -1) {
|
if((encryptedFileLength = (dynamic_cast<crypt*>(O))->aesEncrypt((const unsigned char*)file, fileLength, &encryptedFile) ) == -1) {
|
||||||
fprintf(stderr, "Encryption failed\n");
|
fprintf(stderr, "Encryption failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
@ -51,7 +51,7 @@ int main(int argc, char* argv[]) {
|
|||||||
fprintf(stderr, "Decryption failed\n");
|
fprintf(stderr, "Decryption failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%d bytes decrypted\n", (int)decryptedFileLength);
|
printf("%d bytes decrypted\n", (int)decryptedFileLength);
|
||||||
std::cerr << O2->PrintAesKey() << std::endl;
|
std::cerr << O2->PrintAesKey() << std::endl;
|
||||||
// Write the decrypted file to its own file
|
// Write the decrypted file to its own file
|
||||||
@ -64,4 +64,4 @@ int main(int argc, char* argv[]) {
|
|||||||
delete O;
|
delete O;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,16 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
// Read the file to encrypt
|
// Read the file to encrypt
|
||||||
unsigned char* file;
|
unsigned char* file;
|
||||||
//******************************************************************* while a rajouté pour les gros fichier
|
//******************************************************************* while a rajouté pour les gros fichier
|
||||||
// readFile fait l'aloccation mémoire !!! pensé au free
|
// readFile made memory allocation !!! think to free arg
|
||||||
size_t fileLength = O->readFile(&file);
|
size_t fileLength = O->readFile(&file);
|
||||||
|
|
||||||
printf("%d bytes to be encrypted\n", (int)fileLength);
|
printf("%d bytes to be encrypted\n", (int)fileLength);
|
||||||
|
|
||||||
// Encrypt the file
|
// Encrypt the file
|
||||||
unsigned char *encryptedFile;
|
unsigned char *encryptedFile;
|
||||||
int encryptedFileLength;
|
int encryptedFileLength;
|
||||||
|
|
||||||
if((encryptedFileLength = (dynamic_cast<crypt*>(O))->aesEncrypt((const unsigned char*)file, fileLength, &encryptedFile) ) == -1) {
|
if((encryptedFileLength = (dynamic_cast<crypt*>(O))->aesEncrypt((const unsigned char*)file, fileLength, &encryptedFile) ) == -1) {
|
||||||
fprintf(stderr, "Encryption failed\n");
|
fprintf(stderr, "Encryption failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
@ -40,8 +40,8 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
free(encryptedFile);
|
free(encryptedFile);
|
||||||
free(file);
|
free(file);
|
||||||
//******************************************************************
|
//******************************************************************
|
||||||
delete O;
|
delete O;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ int main(int argc, char* argv[]) {
|
|||||||
std::cerr << "An input file is missing.\n ./Decrypt.ex fileToDecrypt AeskeyForDecrypt\n";
|
std::cerr << "An input file is missing.\n ./Decrypt.ex fileToDecrypt AeskeyForDecrypt\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t fileLength;
|
size_t fileLength;
|
||||||
unsigned char* fileEncrypted;
|
unsigned char* fileEncrypted;
|
||||||
unsigned char* decryptedFile;
|
unsigned char* decryptedFile;
|
||||||
@ -22,7 +22,7 @@ int main(int argc, char* argv[]) {
|
|||||||
fprintf(stderr, "Decryption failed\n");
|
fprintf(stderr, "Decryption failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%d bytes decrypted\n", (int)decryptedFileLength);
|
printf("%d bytes decrypted\n", (int)decryptedFileLength);
|
||||||
std::cerr << O2->PrintAesKey() << std::endl;
|
std::cerr << O2->PrintAesKey() << std::endl;
|
||||||
|
|
||||||
@ -35,4 +35,4 @@ int main(int argc, char* argv[]) {
|
|||||||
delete O2;
|
delete O2;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user