openssl允许通过单个命令(-newkey)生成自签名证书指示生成私钥,-x509指示发出自签名证书而不是签名请求)::
openssl req -x509 -newkey rsa:4096 \
-keyout my.key -passout pass:123456 -out my.crt \
-days 365 \
-subj /CN=localhost/O=home/C=US/emailAddress=me@mail.internal \
-addext "subjectAltName = DNS:localhost,DNS:web.internal,email:me@mail.internal" \
-addext keyUsage=digitalSignature -addext extendedKeyUsage=serverAuth
您可以在单独的步骤中生成私钥和构造自签名证书:
openssl genrsa -out my.key -passout pass:123456 2048
openssl req -x509 \
-key my.key -passin pass:123456 -out my.csr \
-days 3650 \
-subj /CN=localhost/O=home/C=US/emailAddress=me@mail.internal \
-addext "subjectAltName = DNS:localhost,DNS:web.internal,email:me@mail.internal" \
-addext keyUsage=digitalSignature -addext extendedKeyUsage=serverAuth
查看生成的证书:
openssl x509 -text -noout -in my.crt
Java keytool创建PKCS#12存储::
keytool -genkeypair -keystore my.p12 -alias master \
-storetype pkcs12 -keyalg RSA -keysize 2048 -validity 3650 \
-storepass 123456 \
-dname "CN=localhost,O=home,C=US" \
-ext 'san=dns:localhost,dns:web.internal,email:me@mail.internal'
要导出自签名证书,请执行以下操作:
keytool -exportcert -keystore my.p12 -file my.crt \
-alias master -rfc -storepass 123456
查看生成的证书:
keytool -printcert -file my.crt
GnuTLS的certtool不允许从CLI传递不同的属性。我不喜欢乱搞配置文件((