secpassword.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef _RAR_SECURE_PASSWORD_
  2. #define _RAR_SECURE_PASSWORD_
  3. // Store a password securely (if data encryption is provided by OS)
  4. // or obfuscated to make search for password in memory dump less trivial.
  5. class SecPassword
  6. {
  7. private:
  8. void Process(const wchar *Src,size_t SrcSize,wchar *Dst,size_t DstSize,bool Encode);
  9. wchar Password[MAXPASSWORD];
  10. // It is important to have this 'bool' value, so if our object is cleaned
  11. // with memset as a part of larger structure, it is handled correctly.
  12. bool PasswordSet;
  13. public:
  14. SecPassword();
  15. ~SecPassword();
  16. void Clean();
  17. void Get(wchar *Psw,size_t MaxSize);
  18. void Set(const wchar *Psw);
  19. bool IsSet() {return PasswordSet;}
  20. size_t Length();
  21. bool operator == (SecPassword &psw);
  22. // Set to true if we need to pass a password to another process.
  23. // We use it when transferring parameters to UAC elevated WinRAR.
  24. bool CrossProcess;
  25. };
  26. void cleandata(void *data,size_t size);
  27. void SecHideData(void *Data,size_t DataSize,bool Encode,bool CrossProcess);
  28. #endif