【发布时间】:2017-08-03 04:06:24
【问题描述】:
我正在尝试在我的 Azure Web 应用程序中设置数据保护,因此当我在暂存和生产之间切换时,它不会让所有人退出。我坚持使用 Azure 中的自签名证书加密密钥。
我的问题与以下内容非常相关: ASP.Net Core Data Protection API in a Clustered Environment 但是,这个问题的答案对我不起作用,因为我已经走到了这一步。
当我在本地运行它并在我的机器上安装证书时,我的代码工作得非常好,但是当我部署到我的 Azure Web 应用程序时,它不会启动并且只会引发一般错误:
Unhandled Exception: System.Security.Cryptography.CryptographicException: Exception of type 'System.Security.Cryptography.CryptographicException' was thrown.
为了设置我的数据保护,我在 ConfigureServices 中使用以下代码:
// Add data protection
var storageAccount = CloudStorageAccount.Parse(Configuration["BlobStorage:ConnectionString"]);
var client = storageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference(Configuration["DataProtection:ContainerName"]);
container.CreateIfNotExistsAsync().Wait();
services.AddDataProtection()
.SetApplicationName(Configuration["DataProtection:ApplicationName"])
.PersistKeysToAzureBlobStorage(container, Configuration["DataProtection:BlobName"]);
.ProtectKeysWithDpapiNG($"CERTIFICATE=HashId:{Configuration["Authentication:SingingCertThumbprint"]}",
DpapiNGProtectionDescriptorFlags.None);
我使用的证书是自签名的,我已通过网络应用程序上的 SSL 证书部分将其上传到 Azure(但是,正如其他帖子中所建议的,我也尝试了受信任的证书 - 不走运)。
我在我的 Azure Web 应用程序中使用 WEBSITE_LOAD_CERTIFICATES 应用程序设置,所以这也不是问题。
另外值得注意的是,如果我删除了
.ProtectKeysWithDpapiNG($"CERTIFICATE=HashId:{Configuration["Authentication:SingingCertThumbprint"]}",
DpapiNGProtectionDescriptorFlags.None);
然后网络应用程序将启动并正常运行。 但现在我的密钥显然是未加密存储的。
任何帮助将不胜感激,谢谢。
【问题讨论】:
标签: c# asp.net azure ssl data-protection