Source code of Windows XP (NT5)
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.

88 lines
2.7 KiB

  1. //
  2. // MODULE: RegistryPasswords.h
  3. //
  4. // PURPOSE: Handles the storing and retrieval of encrypted passwords in the registry.
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Randy Biley
  9. //
  10. // ORIGINAL DATE: 10-23-98
  11. //
  12. // NOTES: Utilizes CryptoAPI v2.0 to store and retrieve passwords from the registry.
  13. //
  14. // Here are some sample calls.
  15. // {
  16. // // Construct a registry password object.
  17. // CRegistryPasswords pwd( _T("SOFTWARE\\ISAPITroubleShoot"),
  18. // _T("APGTS"), _T("APGTS"), _T("Koshka8Spider") );
  19. // ... or equivalently
  20. // CRegistryPasswords pwd( );
  21. // bool bRetVal;
  22. //
  23. // pwd.WriteKey( _T("StatusAccess"), _T("2The9s") ); // Writes an encrypted password.
  24. // bRetVal= pwd.KeyValidate( _T("StatusAccess"), _T("2The9s1") ); // Returns false.
  25. // bRetVal= pwd.KeyValidate( _T("StatusAccess"), _T("2The9s") ); // Returns true.
  26. // }
  27. //
  28. //
  29. // Version Date By Comments
  30. //--------------------------------------------------------------------
  31. // V3.0 10-23-98 RAB
  32. //
  33. #ifndef __REGISTRYPASSWORDS_19981023_H_
  34. #define __REGISTRYPASSWORDS_19981023_H_
  35. #if _MSC_VER >= 1000
  36. #pragma once
  37. #endif // _MSC_VER >= 1000
  38. #include <windows.h>
  39. #include <wincrypt.h>
  40. #include "apgtsstr.h"
  41. #include "apgts.h"
  42. #define HASH_SEED _T("Koshka8Spider")
  43. class CRegistryPasswords
  44. {
  45. public:
  46. // Assembles all of the CryptAPI components.
  47. CRegistryPasswords(
  48. LPCTSTR szRegSoftwareLoc=REG_SOFTWARE_LOC, // Registry Software Key location.
  49. LPCTSTR szRegThisProgram=REG_THIS_PROGRAM, // Registry Program Name.
  50. LPCTSTR szKeyContainer=REG_THIS_PROGRAM, // Key Container Name.
  51. LPCTSTR szHashString=HASH_SEED // Value used to seed the hash.
  52. );
  53. // Simply calls Destroy().
  54. ~CRegistryPasswords();
  55. // Function to encrypt and then write RegValue to RegKey.
  56. bool WriteKey( const CString& RegKey, const CString& RegValue );
  57. // Function to encrypt a given key.
  58. bool EncryptKey( const CString& RegValue, char** ppBuf, long* plBufLen );
  59. // Function to retrieves and then decrypt the value stored in RegKey,
  60. // compares to RegValue, returns true if equal.
  61. bool KeyValidate( const CString& RegKey, const CString& RegValue );
  62. private:
  63. void Destroy(); // Releases all of the CryptAPI components.
  64. HCRYPTPROV m_hProv; // The handle to a CSP.
  65. HCRYPTHASH m_hHash; // The handle to a hash object.
  66. HCRYPTKEY m_hKey; // The handle to a cryptographic key.
  67. bool m_bAllValid; // A flag when set to true indicates valid handles for the
  68. // three objects above.
  69. CString m_strRegSoftwareLoc; // Registry location e.g. _T("SOFTWARE\\ISAPITroubleShoot")
  70. CString m_strRegThisProgram; // Registry program name e.g. _T("APGTS")
  71. } ;
  72. #endif
  73. //
  74. // EOF.
  75. //