我想在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應用程序將啓動並運行良好。 但現在我的密鑰顯然是未加密存儲的。
任何幫助將不勝感激,謝謝。
感謝您的迴應。讓我稍微高興一點,聽到我不是唯一一個有這個問題的人.. 我試過ProtectKeysWithDpapi,並且可以確認它是有效的。 但是,我需要多個服務器來查看這些數據。所以這對我來說並不是真正的解決方案(因此我爲什麼要使用證書)。 – MitchellNZ
我建議您在Azure反饋網站上發佈此問題。 https://feedback.azure.com – Amor