关于钥匙圈钥匙的困惑

时间:2019-12-16 09:59:02

标签: asp.net-core asp.net-core-2.1 encryption-symmetric data-protection

我正在使用 ASP.NET Core数据保护进行数据保护。 使用解密方法取消保护数据时出现以下错误。

System.Security.Cryptography.CryptographicException: The key {e47ceea6-be1f-440b-b204-64ff5a152552} was not found in the key ring.
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)

我在https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/key-management?view=aspnetcore-2.1#automatic-key-ring-refresh浏览了本文档

那么上面异常中提到的键与您在keyManager.GetAllKeys()结果上获得的键ID相同吗?

文档中的代码示例-

// list all keys in the key ring 
var allKeys = keyManager.GetAllKeys(); 
 Console.WriteLine($"The key ring contains {allKeys.Count} key(s).");
 foreach (var key in allKeys) {
 Console.WriteLine($"Key {key.KeyId:B}: Created = {key.CreationDate:u},IsRevoked = {key.IsRevoked}"); 
}

0 个答案:

没有答案