Cryptography.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. //---------------------------------------------------------------------------
  22. class TEncryption
  23. {
  24. public:
  25. TEncryption(const RawByteString & Key);
  26. ~TEncryption();
  27. static bool IsEncryptedFileName(const UnicodeString & FileName);
  28. void Encrypt(TFileBuffer & Buffer, bool Last);
  29. void Decrypt(TFileBuffer & Buffer);
  30. bool DecryptEnd(TFileBuffer & Buffer);
  31. UnicodeString EncryptFileName(const UnicodeString & FileName);
  32. UnicodeString DecryptFileName(const UnicodeString & FileName);
  33. static int GetOverhead();
  34. static int RoundToBlock(int Size);
  35. static int RoundToBlockDown(int Size);
  36. private:
  37. RawByteString FKey;
  38. RawByteString FSalt;
  39. RawByteString FInputHeader;
  40. RawByteString FOverflowBuffer;
  41. bool FOutputtedHeader;
  42. void * FContext;
  43. void Init(const RawByteString & Key, const RawByteString & Salt);
  44. void Aes(char * Buffer, int Size);
  45. void Aes(RawByteString & Buffer);
  46. void Aes(TFileBuffer & Buffer, bool Last);
  47. void NeedSalt();
  48. void SetSalt();
  49. };
  50. //---------------------------------------------------------------------------
  51. #endif