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.

39 lines
1.1KB

  1. #include "aes.hpp"
  2. #include "decrypt.hpp"
  3. int main(int argc, char* argv[]) {
  4. if(argc != 3) {
  5. std::cerr << "An input file is missing.\n ./Decrypt.ex fileToDecrypt AeskeyForDecrypt\n";
  6. return 1;
  7. }
  8. size_t fileLength;
  9. unsigned char* fileEncrypted;
  10. unsigned char* decryptedFile;
  11. aes* O2 = new decrypt(argv[1]);
  12. O2->importKey(argv[2]);
  13. fileLength = O2->readFile(&fileEncrypted);
  14. std::cerr << "byte to be decrypted : " << fileLength << std::endl;
  15. int decryptedFileLength = (dynamic_cast<decrypt*>(O2))->aesDecrypt(fileEncrypted, fileLength, &decryptedFile);
  16. if( decryptedFileLength == -1) {
  17. fprintf(stderr, "Decryption failed\n");
  18. return 1;
  19. }
  20. printf("%d bytes decrypted\n", (int)decryptedFileLength);
  21. std::cerr << "mainDeCrypt.ex : " << O2->PrintAesKey() << std::endl;
  22. // Write the decrypted file to its own file
  23. std::string decryptedFilename = O2->writeFile(decryptedFile, decryptedFileLength);
  24. printf("Decrypted file written to \"%s\"\n", decryptedFilename.c_str());
  25. free(decryptedFile);
  26. free(fileEncrypted);
  27. delete O2;
  28. return 0;
  29. }