Windows SSL 证书生成详细说明

1. 使用 OpenSSL 生成 SSL 证书

步骤 1: 安装 OpenSSL

  • OpenSSL 下载并安装适用于 Windows 的版本。

步骤 2: 生成私钥

openssl genpkey -algorithm RSA -out private.key -aes256
  • 此命令将生成一个 2048 位的 RSA 私钥,并使用 AES-256 加密。

步骤 3: 创建证书签名请求 (CSR)

openssl req -new -key private.key -out cert.csr
  • 此命令将生成一个 CSR 文件,用于向证书颁发机构 (CA) 申请证书。

步骤 4: 生成自签名证书

openssl x509 -req -days 365 -in cert.csr -signkey private.key -out server.crt
  • 此命令将生成一个有效期为 365 天的自签名证书。

2. 使用 Windows 内置工具生成 SSL 证书

步骤 1: 打开 PowerShell

  • 以管理员身份运行 PowerShell。

步骤 2: 生成自签名证书

New-SelfSignedCertificate -DnsName "example.com" -CertStoreLocation "cert:\LocalMachine\My"
  • 此命令将生成一个自签名证书,并将其存储在本地计算机的证书存储中。

步骤 3: 导出证书

$cert = Get-ChildItem -Path "cert:\LocalMachine\My" | Where-Object { $_.Subject -eq "CN=example.com" }
Export-Certificate -Cert $cert -FilePath "C:\example.cer"
  • 此命令将证书导出为 .cer 文件。

案例:为 IIS 配置 SSL 证书

步骤 1: 生成证书
按照上述步骤生成证书,并确保私钥和证书文件可用。

步骤 2: 导入证书到 IIS

  1. 打开 IIS 管理器。

  2. 在左侧导航树中,选择服务器节点。

  3. 双击“服务器证书”。

  4. 点击“导入”,选择生成的 .pfx.cer 文件,完成导入。

步骤 3: 绑定证书到网站

  1. 在 IIS 管理器中,选择网站。

  2. 点击“绑定”。

  3. 添加绑定,选择 HTTPS 协议,并选择导入的证书。

步骤 4: 测试

  • 在浏览器中访问 https://example.com,确保 SSL 证书正常工作。

通过以上步骤,您可以在 Windows 上生成并配置 SSL 证书。

本篇文章内容来源于:windows ssl证书生成详细说明以及案例