简书链接:aspnetcore导出开发证书玩法
文章字数:194,阅读全文大约需要1分钟

1
dotnet dev-certs https --trust --export-path aa.pem --no-password --format PEM

如下 导出pem格式 公钥和私钥一起生成。

1
2
3
4
5
6
7
8
9
10
11
C:\Users\Administrator>dotnet dev-certs https --trust --export-path aa.pem --no-password --format PEM
Trusting the HTTPS development certificate was requested. A confirmation prompt will be displayed if the certificate was not previously trusted. Click yes on the prompt to trust the certificate.
Successfully trusted the existing HTTPS certificate.

C:\Users\Administrator>dotnet dev-certs https --trust --export-path aa.pem --no-password --format PEM

C:\Users\Administrator>dir|findstr aa
2024/05/23 15:34 1,703 aa.key
2024/05/23 15:34 1,118 aa.pem

C:\Users\Administrator>

官方文档中 ,pem为私钥部分
image.png

更多命令如下

1
2
3
4
5
6
7
dotnet dev-certs https 
[-c|--check] [--clean] [-ep|--export-path <PATH>]
[--format] [-i|--import] [-np|--no-password]
[-p|--password] [-q|--quiet] [-t|--trust]
[-v|--verbose] [--version]

dotnet dev-certs https -h|--help

生成crt

1
dotnet dev-certs https -ep ./certificate.crt -p $CREDENTIAL_PLACEHOLDER$ --trust --format PEM

更多参考文档
https://learn.microsoft.com/zh-cn/dotnet/core/tools/dotnet-dev-certs
在 ASP.NET Core 中强制使用 HTTPS | Microsoft Learn
https://learn.microsoft.com/zh-cn/aspnet/core/security/authentication/certauth?view=aspnetcore-8.0