Sco*_*000 1 .net encryption .net-core asp.net-core
我正在尝试将 asp.net 核心 DataProtectionProvider 与支持服务器场的单个数据库一起使用。我为商店实现了一个 IXmlRepository,我成功地向运行我的服务器的两台机器提供了相同的证书。我确认我正在以相同的顺序使用相同用途的字符串,但是当我尝试从机器 a 编码的机器 ba 字符串中取消保护时,我得到了一个通用的 CryptographicException。
如果机器 a 和机器 b 是 2 个不同的操作系统,这有关系吗?(Linux 与 Windows 服务器)
我得到的例外是:
{System.Security.Cryptography.CryptographicException:抛出了“System.Security.Cryptography.CryptographicException”类型的异常。在 Microsoft.AspNetCore.Cryptography.UnsafeNativeMethods.ThrowExceptionForBCryptStatusImpl(Int32 ntstatus) 在 Microsoft.AspNetCore.Cryptography.UnsafeNativeMethods.ThrowExceptionForBCryptStatus(Int32 ntstatus) 在 Microsoft.AspNetCore.DataProtection.Cng.Gcm. pbAdditionalAuthenticatedData, UInt32 cbAdditionalAuthenticatedData)
在 Microsoft.AspNetCore.DataProtection.Cng.Internal.CngAuthenticatedEncryptorBase.Decrypt(ArraySegment)1 ciphertext, ArraySegment1 个额外的 AuthenticatedData) 在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status) 在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector,[Dangerer , Boolean& wasRevoked) 在 Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData) 在 Microsoft.AspNetCore.DataProtection.DataProtectionCommonExtensions.Unprotect(IDataProtectorprotector, String protectedData)
我发现提供者具有用于顶级目的的文件夹名称。我假设这是在存储在注册表中时隔离密钥存储。解决方案是将 ApplicationName 添加到配置设置中,以便它使用它而不是两台不同机器上不同的文件夹。
例子:
services.AddDataProtection()
.UseCryptographicAlgorithms(new AuthenticatedEncryptorConfiguration()
{
EncryptionAlgorithm = EncryptionAlgorithm.AES_256_GCM,
ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
})
.SetApplicationName("MyCommonName");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1425 次 |
| 最近记录: |