【发布时间】:2017-06-12 19:49:04
【问题描述】:
我部署了一个 webjob (.Net 4.6),它会加密一些 url 字符串并通过电子邮件将其发送给客户。我使用 .NET Core 的 IDataProtector 进行加密,我不得不手动引用 DLL,因为 webjob .net 4.6 不支持它的库。
例如在 webjob 中:
IDataProtector protector = provider.CreateProtector("myProtector")
http://test.com/Email/Agreement?n=" + protector.Protect(name) + "&a=" + protector.Protect(address)
变成链接
http://test.com/Email/Agreement?n=CfDJ8AAAAAAAAAAAAAAAAAAAAAD96g09022UwEG-GyVftzkm-n2JuL1hmvL5HLyghXliIgJ_N014EBqBFfWjmdA&a=CfDJ8AAAAAAAAAAAAAAAAAAAAAALoq9IuMBZKozhzH3jRaHpyFE1wtXzQK3T_0RNuX9LsSVxPITWgU9ZR21jXLk3YGjt
在电子邮件中。
当客户点击他们电子邮件中的 url 链接时,它会转到我的客户端应用程序的 (.Net Core 1.1) 控制器来解密 url 字符串以弹出协议页。
例如:
public EmailController(IDataProtectionProvider provider)
{
_protector = provider.CreateProtector("myProtector");
}
public IActionResult Agreement(string n, string a)
{
var decryptName = _protector.Unprotect(n);
var decryptAddress = _protector.Unprotect(a);
}
但是,当我尝试取消保护它们时,我收到以下错误消息:
System.Security.Cryptography.CryptographicException: '在密钥环中找不到密钥 {00000000-0000-0000-0000-000000000000}。'
当我搜索答案时,我意识到我可以配置数据保护以将密钥存储到 Azure Blob 存储。这个link 向我展示了如何将密钥持久保存到 azure blob 存储。
问题:
- 除了将密钥存储到 Azure Blob 存储之外,最好的方法是什么?
- 如果我在正确的轨道上,我该如何存储它?
- 如何为 webjob 项目配置与没有 Startup.cs 进行配置的链接中所示相同的设置?
非常感谢您的帮助。
【问题讨论】:
标签: azure-webjobs data-protection azure-blob-storage asp.net-core-1.1 cryptographicexception