跨机器加密/解密是禁止的
时间:2020-03-05 18:53:50 来源:igfitidea点击:
我在XP和Vista之间使用对" CryptUnprotectData"(从Crypt32.dll公开)的相同调用。在XP中工作正常。在Vista中运行时,出现以下异常:
"Decryption failed. Key not valid for use in specified state."
如预期的那样,XP和Vista之间的crypt32.dll版本是不同的(实际上是带有XP的较新版本,可能是SP3或者其他更新)。
更具体地说,我正在加密数据,将其放入注册表中,然后使用" CryptUnprotectData"进行读取和解密。 UAC已关闭。
有人看过吗?
解决方案
回答
CryptUnprotectData函数文档指出,它通常仅在用户具有与加密程序相同的登录凭据时才起作用。
这向我表明,密钥可能与用户当前的令牌绑定在一起。自从我们提到Vista以来,这使我想到了UAC和受限令牌。
你能给我们看一些代码吗?我们能否向我们提供有关我们正在处理数据的更多信息-即我们是在进程,用户还是计算机之间移动它?
回答
好的。希望这是我本周的明智之举! ;-)
This suggests to me that maybe the key is tied to the user's current token.
就是这样原来我正在使用另一台计算机(XP)上的加密数据,并试图在Vista计算机上解密。
正如MSDN文档所述:
Usually, only a user with the same logon credentials as the encrypter can decrypt the data. In addition, the encryption and decryption must be done on the same computer.
一旦我在Vista机器上重新加密了数据,解密就会按预期进行。
谢谢。