Leaked source code of windows server 2003
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.

77 lines
1.3 KiB

  1. /*++
  2. Copyright (c) 2003 Microsoft Corporation
  3. Module Name:
  4. xstring.h
  5. Abstract:
  6. Author:
  7. Stephen A Sulzer (ssulzer) 16-Jan-2003
  8. --*/
  9. //
  10. // class implementation of CSecureString
  11. //
  12. class CSecureStr
  13. {
  14. LPSTR _lpsz;
  15. int _stringLength;
  16. bool _fEncryptString;
  17. bool _fOwnString;
  18. public:
  19. CSecureStr()
  20. {
  21. _lpsz = NULL;
  22. _stringLength = 0;
  23. _fEncryptString = true;
  24. _fOwnString = true;
  25. }
  26. CSecureStr(LPSTR lpszEncryptedString, int stringLength, bool fOwnString)
  27. {
  28. _lpsz = lpszEncryptedString;
  29. _stringLength = stringLength;
  30. _fEncryptString = true;
  31. _fOwnString = fOwnString;
  32. }
  33. ~CSecureStr()
  34. {
  35. Free();
  36. }
  37. void Free (void)
  38. {
  39. if (_lpsz && _fOwnString)
  40. {
  41. SecureZeroMemory(_lpsz, _stringLength);
  42. delete [] _lpsz;
  43. }
  44. _lpsz = NULL;
  45. _stringLength = 0;
  46. }
  47. LPSTR GetPtr(void)
  48. {
  49. return _lpsz;
  50. }
  51. DWORD GetStrLen() const // returns length of encrypted string
  52. {
  53. return _stringLength;
  54. }
  55. LPSTR GetUnencryptedString(); // always allocates memory regardless of _fEncryptString
  56. BOOL SetData(LPSTR lpszIn);
  57. };