使用Openssl一键生成pem和der证书

将以下代码另存为后缀名为sh的文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
PASS=
Init_Selection() {
clear
echo "+------------------------------------------------------------------------+"
echo "| _ _ _ _ _ _ _ _ |"
echo "| / / //_|/_//_//_//_//_'/ //_/ |"
echo "| _/ / _/ |"
echo "+------------------------------------------------------------------------+"
echo "| openssl证书生成脚本v1.0 |"
echo "+------------------------------------------------------------------------+"
echo "| https://www.maoyupeng.club |"
echo "+------------------------------------------------------------------------+"

Echo_Green "请输入证书密码"
read -p "Password:" PASS
action_build

}

action_build()
{
echo "创建AES256加密密钥..."
openssl genrsa -passout pass:${PASS} -out rsa_aes_private.pem 2048
echo "生成公钥..."
openssl rsa -in rsa_aes_private.pem -passin pass:${PASS} -pubout -out rsa_public.pem
echo "PEM私钥转DER..."
openssl rsa -in rsa_aes_private.pem -passin pass:${PASS} -out rsa_private_key.der -outform der
echo "PEM公钥转DER..."
openssl rsa -in rsa_public.pem -out rsa_public_key.der -pubin -outform der
echo "Finish!"

}


Echo_Green()
{
echo $(Color_Text "$1" "32")
}

Echo_Yellow()
{
echo $(Color_Text "$1" "33")
}

Init_Selection

然后打开终端, 赋予权限

1
chmod -R 755 ./*.sh

最后执行脚本文件, 根据提示输入生成证书的密码

1
./xxx.sh

等待片刻, 证书生成成功

坚持原创技术分享,您的支持将鼓励我继续创作!对, 你想得对, 我真的缺你的这几块钱!
0%