我正在使用 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)
那么上面异常中提到的键与您在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}");
}