Win32 CryptProtectData 方法
Win32 CryptProtectData Method
我正在读这个:https://docs.microsoft.com/en-us/windows/win32/seccrypto/example-c-program-using-cryptprotectdata
我想知道这个方法。这是否仅在进程 运行 时将其存储在进程内存中?如果是这样,是否存在 win32 api 提供的安全且不会在文件系统上创建任何文件的持久数据存储?某种安全的 keychain/keyvalue 商店?
我的目的是保护一个安全的登录令牌,我正在为用户编写的程序可以使用该令牌两周进行登录。我认为这些数据不应存储在任何人都可以访问的文件中。如果有人发现了该文件,只要令牌有效,他们就可以窃取该文件并使用其他人的帐户登录。环境变量和 windows 注册表也不是可接受的解决方案。这需要用户无法访问。
将您的登录令牌存储在文件中(或在我个人更喜欢的注册表中)没有任何问题,前提是您正确地对其进行了加密。 CryptProtectData
的 documentation 是这样说的:
Typically, only a user with the same logon credential as the user who encrypted the data can decrypt the data. In addition, the encryption and decryption usually must be done on the same computer.
所以你已经完成了一半。只有 'own' 令牌的用户(和机器)才能解密它。
除此之外,还有这个参数:
[in, optional] pOptionalEntropy
A pointer to a DATA_BLOB structure that contains a password or other additional entropy used to encrypt the data. The [same] DATA_BLOB structure used in the encryption phase must also be used in the decryption phase
所以这应该是只有您的程序知道的东西(GUID 是显而易见的选择)。然后,只有该程序才能解密并因此使用令牌。
您可以在您的代码中采取一些步骤来混淆它,例如以某种损坏的形式存储它并且只在您使用它之前对其进行分解。然后在完成后调用 SecureZeroMemory
,让潜在的窥探者的日子更难过。
我正在读这个:https://docs.microsoft.com/en-us/windows/win32/seccrypto/example-c-program-using-cryptprotectdata
我想知道这个方法。这是否仅在进程 运行 时将其存储在进程内存中?如果是这样,是否存在 win32 api 提供的安全且不会在文件系统上创建任何文件的持久数据存储?某种安全的 keychain/keyvalue 商店?
我的目的是保护一个安全的登录令牌,我正在为用户编写的程序可以使用该令牌两周进行登录。我认为这些数据不应存储在任何人都可以访问的文件中。如果有人发现了该文件,只要令牌有效,他们就可以窃取该文件并使用其他人的帐户登录。环境变量和 windows 注册表也不是可接受的解决方案。这需要用户无法访问。
将您的登录令牌存储在文件中(或在我个人更喜欢的注册表中)没有任何问题,前提是您正确地对其进行了加密。 CryptProtectData
的 documentation 是这样说的:
Typically, only a user with the same logon credential as the user who encrypted the data can decrypt the data. In addition, the encryption and decryption usually must be done on the same computer.
所以你已经完成了一半。只有 'own' 令牌的用户(和机器)才能解密它。
除此之外,还有这个参数:
[in, optional] pOptionalEntropy
A pointer to a DATA_BLOB structure that contains a password or other additional entropy used to encrypt the data. The [same] DATA_BLOB structure used in the encryption phase must also be used in the decryption phase
所以这应该是只有您的程序知道的东西(GUID 是显而易见的选择)。然后,只有该程序才能解密并因此使用令牌。
您可以在您的代码中采取一些步骤来混淆它,例如以某种损坏的形式存储它并且只在您使用它之前对其进行分解。然后在完成后调用 SecureZeroMemory
,让潜在的窥探者的日子更难过。