文章目录
- 正常RSA密钥对生成操作命令
openssl genrsa -out rsa_private_key.pem 2048
openssl rsa -pubout -in rsa_private_key.pem -out rsa_public_key.pem
- 通过添加环境变量来简化RSA密钥对生成操作
设置环境变量.zshrc或.bash_profile
# 使用zsh终端
vim ~/.zshrc
- 将下面shell脚本复制到.zshrc文件中
function myrsa() {if [ -z $1 ]; thenecho "请输入密钥名称"returnfi# 512位、1024位、2048位、3072位、4096位len=2048if [ -n "$2" ]; thenlen=$2fiprivateKey=$1"_rsa_private_key.pem"publicKey=$1"_rsa_public_key.pem"openssl genrsa -out $privateKey $lenopenssl rsa -pubout -in $privateKey -out $publicKeyecho $(pwd)echo $privateKeyecho $publicKey
}
source ~/.zshrc
- 执行简化后的生成命令
# 终端输入生成RSA密钥对命令
myrsa test
- 生成的RSA密钥
test_rsa_private_key.pem
test_rsa_public_key.pem