开发者社区> 问答> 正文

Ubuntu上的ASP.NET Core 2.2 Web应用程序-如何实施数据保护

我已经开始使用Ubuntu(18.04)托管一些简单的.NET Core 2.2网站。部署并启动该站点后,我将看到以下内容:

警告:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager [59]用户配置文件和HKLM注册表均不可用。使用临时密钥存储库。当应用程序退出时,受保护的数据将不可用。警告:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager [35]未配置XML加密器。密钥{c45288a6-63f8-4408-abdb-7894fb6d4e45}可以以未加密形式持久存储。托管环境:生产内容根目录路径:/ var / www / mysite现在正在监听:http:// localhost:5010 应用程序已启动。按Ctrl + C关闭。警告:Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware [3]无法确定用于重定向的https端口。

那么,为Linux(以及可能也适用于Windows)实现密钥存储提供程序的最佳且安全的方法是什么?有没有现有的?有什么例子吗?

PS。是的,我看过此文档-ASP.NET Core中的密钥存储提供程序。

展开
收起
祖安文状元 2020-01-05 19:05:24 752 0
1 条回答
写回答
取消 提交回答
  • 我们使用Azure ATS作为关键存储库来实现此方法以及支持负载平衡方案的方法。

    配置看起来像这样:

    string storageUrl = "https://[your account here].blob.core.windows.net";
      string sasToken = "?sv=20XX-XX-XX&ss=x&srt=xxx&sp=xxxx&...";
      string containerName = "data-protection-XXXX-XXXX-container";
      string blobName = "data-protection-XXXX-XXXX-blob";
    
       // Create the new Storage URI
       Uri storageUri = new Uri($"{storageUrl}{sasToken}");
    
       //Create the blob client object.
       CloudBlobClient blobClient = new CloudBlobClient(storageUri);
    
       //Get a reference to a container. Create it if it does not exist.
       CloudBlobContainer container = blobClient.GetContainerReference(containerName);
    
       // (NOTE: internal library, do not use in your code)
       AsyncHelper.Guarded<bool>(() => { return container.CreateIfNotExistsAsync();  });
    
    
       services.AddDataProtection()
            .SetApplicationName("[your application name here]")
            .PersistKeysToAzureBlobStorage(container, blobName)
            .SetDefaultKeyLifetime(new TimeSpan(365 * 10, 0, 0, 0, 0));
    
    

    注意:配置数据保护以提高安全性时,请查看加密选项。

    2020-01-05 19:05:33
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
从Web到Cloud App——YunOS Web App 开发经验分享 立即下载
Web应用系统性能优化 立即下载
从Web到Cloud App 立即下载