aes/mainCrypt.cpp
2020-04-27 23:13:55 +02:00

47 lines
1.4 KiB
C++

#include "aes.hpp"
#include "crypt.hpp"
int main(int argc, char* argv[]) {
if(argc != 2) {
std::cerr << "No file argument supplied.\n";
return 1;
}
char* filename = argv[1];
aes* O = new crypt(filename);
// Read the file to encrypt
unsigned char* file;
//******************************************************************* while a rajouté pour les gros fichier
// readFile made memory allocation !!! think to free arg
size_t fileLength = O->readFile(&file);
printf("%d bytes to be encrypted\n", (int)fileLength);
// Encrypt the file
unsigned char *encryptedFile;
int encryptedFileLength;
if((encryptedFileLength = (dynamic_cast<crypt*>(O))->aesEncrypt((const unsigned char*)file, fileLength, &encryptedFile) ) == -1) {
fprintf(stderr, "Encryption failed\n");
return 1;
}
printf("%d bytes encrypted\n", encryptedFileLength);
std::cerr << "mainCrypt.ex : " << O->PrintAesKey() << std::endl;
std::string keyFilename = O->exportKey();
printf("Encrypt key written to \"%s\"\n", keyFilename.c_str());
// Write the encrypted file to its own file
std::string encryptedFilename = O->writeFile(encryptedFile, encryptedFileLength);
printf("Encrypted message written to \"%s\"\n", encryptedFilename.c_str());
free(encryptedFile);
free(file);
//******************************************************************
delete O;
return 0;
}