一、生成证书
1. 安装 OpenSSL
如果尚未安装 OpenSSL,可以通过以下命令安装:
Ubuntu/Debian:
sudo apt update
sudo apt install openssl
CentOS/RHEL:
sudo yum install openssl
2. 生成私钥
使用以下命令生成私钥文件(private.key):
openssl genpkey -algorithm RSA -out private.key
3. 生成证书签名请求(CSR)
使用以下命令生成 CSR 文件(certificate.csr):
openssl req -new -key private.key -out certificate.csr
在生成 CSR 时,会提示你输入一些信息,如国家代码、组织名称、域名等。
4. 生成自签名证书
使用以下命令生成自签名证书(certificate.crt):
openssl x509 -req -days 365 -in certificate.csr -signkey private.key -out certificate.crt
5. 打包为 .pfx 文件
使用以下命令将私钥和证书打包为 .pfx 文件:
openssl pkcs12 -export -out certificate.pfx -inkey private.key -in certificate.crt
系统会提示你设置 .pfx 文件的密码,请记住这个密码,后续在 .NET Core 中配置 HTTPS 时需要用到。


netcore中使用

浏览器查看证书:
