password manager with aes encryption
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4KB

  1. #include "aes.hpp"
  2. #include "crypt.hpp"
  3. int main(int argc, char* argv[]) {
  4. if(argc != 2) {
  5. std::cerr << "No file argument supplied.\n";
  6. return 1;
  7. }
  8. char* filename = argv[1];
  9. aes* O = new crypt(filename);
  10. // Read the file to encrypt
  11. unsigned char* file;
  12. //******************************************************************* while a rajouté pour les gros fichier
  13. // readFile made memory allocation !!! think to free arg
  14. size_t fileLength = O->readFile(&file);
  15. printf("%d bytes to be encrypted\n", (int)fileLength);
  16. // Encrypt the file
  17. unsigned char *encryptedFile;
  18. int encryptedFileLength;
  19. if((encryptedFileLength = (dynamic_cast<crypt*>(O))->aesEncrypt((const unsigned char*)file, fileLength, &encryptedFile) ) == -1) {
  20. fprintf(stderr, "Encryption failed\n");
  21. return 1;
  22. }
  23. printf("%d bytes encrypted\n", encryptedFileLength);
  24. std::cerr << "mainCrypt.ex : " << O->PrintAesKey() << std::endl;
  25. std::string keyFilename = O->exportKey();
  26. printf("Encrypt key written to \"%s\"\n", keyFilename.c_str());
  27. // Write the encrypted file to its own file
  28. std::string encryptedFilename = O->writeFile(encryptedFile, encryptedFileLength);
  29. printf("Encrypted message written to \"%s\"\n", encryptedFilename.c_str());
  30. free(encryptedFile);
  31. free(file);
  32. //******************************************************************
  33. delete O;
  34. return 0;
  35. }