如何在 Windows 中创建具有 SAN 和特定加密的证书?

如何在 Windows 中创建具有 SAN 和特定加密的证书?

我想要创建一个包含以下内容的证书:

  1. 主题备用名称
  2. SHA256 作为哈希算法

在 Windows 10 Ent 计算机上,创建证书时上述两个选项默认不可用。SAN 选项不存在,默认证书使用 SHA1 加密。

如何在 Windows 中启用这些选项的选择?

答案1

最后,我只是使用了 openssl(为 Windows 下载的二进制文件)和一个配置文件。

创建 CSR 的第一个命令是:

openssl req -out sslcert.csr -newkey rsa:2048 -nodes -keyout private.key -config my.cnf

在哪里:

sslcert.csr would be the CSR to send to client 
private.key would be the key you want to keep it with you and not share. will come handy when the client gets back to you with the certificate response 
my.cnf would be the file that allows you to add SAN values, hash alogrithm etc.

示例 my.cnf 中的值可以根据您自己的要求进行替换。

 [ req ] 
 default_bits       = 2048 distinguished_name =
 req_distinguished_name req_extensions     = req_ext
 
 prompt         = no
 
 [ req_distinguished_name ] 
 countryName                 = value
 stateOrProvinceName         = value 
 localityName               = value
 organizationName           = value 
 organizationalUnitName     = value
 commonName                 = value

 [ req_ext ] 
 subjectAltName = @alt_names 

 [alt_names] DNS.1 = value

注意:在创建 csr 之后并将其发送给客户端之前检查它以确保所有值都是正确的,这是一个好主意。只需谷歌搜索“检查 csr”,您就可以使用任何在线工具来验证值是否正确。

当客户端带着完整的 CSR 返回时,您将运行以下命令来完成证书:

openssl pkcs12 -export -name "clientcert" -out yourdomain.pfx -inkey private.key -in yourdomain.crt

在哪里:

clientcert would be the friendly name for the certifiate
yourdomain.pfx would be the certificate for the domain
yourdomain.crt would be the response client gave you

系统会要求您创建密码,请创建(安全性高),证书将采用 pfx 格式。因此,有了密码和 pfx,您就可以将其带到您的应用程序中进行安装。

答案2

您可以使用 PowerShell 来实现此目的:

New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName "<YOUR SN>,<2ND SAN><3RD SAN>" -FriendlyName "<YOUR CRT NAME>" -NotAfter (Get-Date).AddYears(10)

相关内容