網站首頁 編程語言 正文
開發時使用的?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);
}
如果有用請點贊,轉載請說明出處,謝謝!!
原文鏈接:https://blog.csdn.net/m0_62367247/article/details/127033649
相關推薦
- 2023-04-11 pandas中實現將相同ID的字符串進行合并_python
- 2022-03-31 C語言取模取整的深入理解_C 語言
- 2022-09-15 python?Pandas庫read_excel()參數實例詳解_python
- 2023-03-25 Go語言基于viper實現apollo多實例快速_Golang
- 2022-11-23 pytorch?tensorboard可視化的使用詳解_python
- 2022-05-01 使用GoogleContainerTools容器化jib構建docker鏡像_docker
- 2022-04-16 python字符串不可變數據類型_python
- 2022-08-02 Go語言resty?http包調用jenkins?api實例_Golang
- 最近更新
-
- 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同步修改后的遠程分支