網站首頁 編程語言 正文
開發時使用的?AddDeveloperSigningCredential(),不適合生產環境。
戳幾字,簡單使用PowerShell讀取.CER 文件, 使用.NET X509Certificate2這個類,生成、讀取、刪除證書。
1.?打開cmd,然后輸入powershell切換為powershell
?
2. 讀取證書
輸入 Get-ChildItem -Path cert:\CurrentUser\My?
?目前有3個證書
3.創建證書
輸入?New-SelfSignedCertificate -Subject "CN=IDS4_Certificate" -CertStoreLocation cert:\CurrentUser\My -Provider "Microsoft Strong Cryptographic Provider"
名為 IDS4_Certificate
4.刪除證書
輸入?Remove-Item -Path ("cert:\CurrentUser\My\" + $cert.Thumbprint)
?(先試試增 刪 查 這幾步驟,后面就不重復了)
重點部分
5. 導出秘鑰文件
a. 根據以上步驟先創建一個證書,名為 IDS4_Certificate,?輸入
New-SelfSignedCertificate -Subject "CN=IDS4_Certificate" -CertStoreLocation cert:\CurrentUser\My -Provider "Microsoft Strong Cryptographic Provider"
b. 加載剛生成的證書,輸入
??$cert = Get-ChildItem -Path cert:\CurrentUser\My\(your certificate thumbprint)
c.導出公鑰到項目文件夾,輸入
Export-Certificate -Type CERT -Cert $cert -FilePath "./publickey.cer"
d.導出私鑰到項目文件夾
輸入 $cred = Get-Credential 配置秘鑰
?輸入??Export-PfxCertificate -Cert $cert -Password $cred.Password -FilePath "./private.pfx"
Finish
配置identity server4 使用生成的證書
private readonly IConfiguration _configuration;
private readonly IHostEnvironment _environment;
private readonly IWebHostEnvironment _webHostEnv;
public Startup(IConfiguration configuration, IHostEnvironment environment, IWebHostEnvironment webHostEnvironment)
{
_configuration = configuration;
_environment = environment;
_webHostEnv = webHostEnvironment;
}
IIdentityServerBuilder identityServerBuilder = services.AddIdentityServer();
//開發環境時
if (_environment.IsDevelopment())
{
identityServerBuilder.AddDeveloperSigningCredential(); //配置臨時憑據
}
else
{
string certPath = Path.Combine(_webHostEnv.ContentRootPath, "private.pfx");
var certificate = new X509Certificate2(certPath, "test");
identityServerBuilder.AddSigningCredential(certificate);
}
如果有用請點贊,轉載請說明出處,謝謝?。?/p>
原文鏈接:https://blog.csdn.net/m0_62367247/article/details/127033649
相關推薦
- 2023-07-26 webpack提供構建速度之打包開啟多進程(thead)
- 2023-03-16 python中asyncore異步模塊的實現_python
- 2022-07-19 Docker容器內存占用過高解決方法
- 2022-05-13 類實例化 對象的內存模型 及 內存占用分析
- 2022-09-12 Go1.18新特性工作區模糊測試及泛型的使用詳解_Golang
- 2022-09-29 React路由攔截模式及withRouter示例詳解_React
- 2022-11-16 python壓縮和解壓縮模塊之zlib的用法_python
- 2022-04-10 Blazor實現數據驗證_基礎應用
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支