Cryptography.h 2.2 KB

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