2017-08-03 108 views
2

我想在Azure Web应用程序中设置数据保护,因此当我在分段和生产之间交换时,它不会记录每个人。我坚持使用Azure中的自签名证书对密钥进行加密。Azure Web App中的ASP.Net核心数据保护API

我的问题是有很大关系: ASP.Net Core Data Protection API in a Clustered Environment 然而,在这个答案不适合我,因为我已经得到了这个工作至今。


我的代码工作完全正常,当我安装我的machince证书在本地运行,但是当我部署到我的Azure的Web应用程序,它不会启动,只是抛出一个一般性错误:

Unhandled Exception: System.Security.Cryptography.CryptographicException: Exception of type 'System.Security.Cryptography.CryptographicException' was thrown. 

// 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); 

我使用的证书:

设置我的数据保护,我现在用的是在ConfigureServices下面的代码自签名,并且我已通过Web应用程序中的SSL证书部分将其上载到Azure(但是,如其他帖子中所建议的,我也尝试了可信证书 - 没有运气)。

我在我的Azure网络应用中使用了WEBSITE_LOAD_CERTIFICATES应用设置,所以这也不是问题。

另外值得注意的,如果我删除

.ProtectKeysWithDpapiNG($"CERTIFICATE=HashId:{Configuration["Authentication:SingingCertThumbprint"]}", 
    DpapiNGProtectionDescriptorFlags.None); 

那么Web应用程序将启动并运行良好。 但现在我的密钥显然是未加密存储的。

任何帮助将不胜感激,谢谢。

回答

1

我也遇到了同样的问题。我尝试将平台更改为64位,并扩展了我的应用程序计划,但没有一个可行。 ProtectKeysWithDpapiNG可能不受Azure Web App的支持。我建议你改用ProtectKeysWithDpapi。密钥将由Windows DPAPI加密。

+0

感谢您的回应。让我稍微高兴一点,听到我不是唯一一个有这个问题的人.. 我试过ProtectKeysWithDpapi,并且可以确认它是有效的。 但是,我需要多个服务器来查看这些数据。所以这对我来说并不是真正的解决方案(因此我为什么要使用证书)。 – MitchellNZ

+0

我建议您在Azure反馈网站上发布此问题。 https://feedback.azure.com – Amor