Last active
August 10, 2023 09:38
-
-
Save yulewei/4ca53480591034487c402d3912e0301a to your computer and use it in GitHub Desktop.
生成 pkcs8 格式的 RSA 公钥和私钥
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 生成私钥,默认 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