Cryptography.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //---------------------------------------------------------------------------
  2. #ifndef CryptographyH
  3. #define CryptographyH
  4. //---------------------------------------------------------------------------
  5. void __fastcall CryptographyInitialize();
  6. void __fastcall CryptographyFinalize();
  7. RawByteString __fastcall ScramblePassword(UnicodeString Password);
  8. bool __fastcall UnscramblePassword(RawByteString Scrambled, UnicodeString & Password);
  9. void __fastcall AES256EncyptWithMAC(RawByteString Input, UnicodeString Password,
  10. RawByteString & Output);
  11. bool __fastcall AES256DecryptWithMAC(RawByteString Input, UnicodeString Password,
  12. RawByteString & Output);
  13. void __fastcall AES256CreateVerifier(UnicodeString Input, RawByteString & Verifier);
  14. bool __fastcall AES256Verify(UnicodeString Input, RawByteString Verifier);
  15. int __fastcall IsValidPassword(UnicodeString Password);
  16. int __fastcall PasswordMaxLength();
  17. RawByteString GenerateEncryptKey();
  18. void ValidateEncryptKey(const RawByteString & Key);
  19. //---------------------------------------------------------------------------
  20. class TFileBuffer;
  21. typedef void AESContext;
  22. //---------------------------------------------------------------------------
  23. class TEncryption
  24. {
  25. public:
  26. TEncryption(const RawByteString & Key);
  27. ~TEncryption();
  28. static bool IsEncryptedFileName(const UnicodeString & FileName);
  29. void Encrypt(TFileBuffer & Buffer, bool Last);
  30. void Decrypt(TFileBuffer & Buffer);
  31. bool DecryptEnd(TFileBuffer & Buffer);
  32. UnicodeString EncryptFileName(const UnicodeString & FileName);
  33. UnicodeString DecryptFileName(const UnicodeString & FileName);
  34. static int GetOverhead();
  35. static int RoundToBlock(int Size);
  36. static int RoundToBlockDown(int Size);
  37. private:
  38. RawByteString FKey;
  39. RawByteString FSalt;
  40. RawByteString FInputHeader;
  41. RawByteString FOverflowBuffer;
  42. bool FOutputtedHeader;
  43. AESContext * FContext;
  44. void Init(const RawByteString & Key, const RawByteString & Salt);
  45. void Aes(char * Buffer, int Size);
  46. void Aes(RawByteString & Buffer);
  47. void Aes(TFileBuffer & Buffer, bool Last);
  48. void NeedSalt();
  49. void SetSalt();
  50. };
  51. //---------------------------------------------------------------------------
  52. #endif