Skip to content

2024‐07‐02‐openssl‐cheatsheet

應卓 edited this page Jul 2, 2024 · 1 revision

以下脚本可以生成EC,RSA,DSA用的密钥对。

#!/usr/bin/env bash

openssl genrsa -out keypair.rsa.key 2048
openssl rsa -in keypair.rsa.key -pubout -outform PEM -out rsa-public-key-x509.pem
openssl pkcs8 -topk8 -inform PEM -outform PEM -in keypair.rsa.key -out rsa-private-key-pkcs8.pem -nocrypt

# openssl ecparam -list_curves
openssl ecparam -name prime256v1 -genkey -noout -out private.ec.key
openssl pkcs8 -topk8 -in private.ec.key -out ecdsa-private-key-pkcs8.pem -nocrypt
openssl ec -in ecdsa-private-key-pkcs8.pem -pubout -out ecdsa-public-key-x509.pem

openssl dsaparam -out private.dsa.key -genkey 1024
openssl pkcs8 -topk8 -in private.dsa.key -out dsa-private-key-pkcs8.pem -nocrypt
openssl dsa -in dsa-private-key-pkcs8.pem -pubout -out dsa-public-key-x509.pem