Skip to content

Instantly share code, notes, and snippets.

@yulewei
Last active Mar 5, 2020
Embed
What would you like to do?
生成 pkcs8 格式的 RSA 公钥和私钥
# 生成私钥,默认 pkcs1 格式
openssl genrsa -out private_key_pkcs1.pem 1024
# 生成公钥,默认 pkcs8 格式
openssl rsa -pubout -in private_key_pkcs1.pem -out public_key_pkcs8.pem
# 私钥转 pkcs8 格式
openssl pkcs8 -topk8 -in private_key_pkcs1.pem -inform pem -out private_key_pkcs8.pem -outform pem -nocrypt
# 只保留 pem 文件中的 base64 内容
cat private_key_pkcs8.pem | sed '1d;$d' | tr -d '\n' > private_key.txt
cat public_key_pkcs8.pem | sed '1d;$d' | tr -d '\n' > public_key.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment