近期在配置https工單時,遇到兩起客戶提供的crt非標準,須要根據p7b及crt文件手動從p7b文件以base64編碼逐個導出證書後拼接爲新的crt,過程較繁瑣。爲提高效率,總結了p7b轉換crt的方法,步驟以下:bash
以1.a.com.p7b證書爲例,轉換爲1.a.com.crtide
fold -w 64 1.a.com.p7b > temp.p7b
openssl pkcs7 -print_certs -in temp.p7b |grep -Ev '^\s*$|subject|issuer' > 1.a.com.crt
對應腳本編碼
#!/bin/bash p7b_file="$1" p7b_filename=$(echo ${p7b_file} |sed -r 's#(.*).p7b#\1#g') usage () { echo "Usage:sh $0 p7b_file" exit 0 } [ $# -ne 1 ] && usage fold -w 64 ${p7b_file} > temp.p7b openssl pkcs7 -print_certs -in temp.p7b |grep -Ev '^\s*$|subject|issuer' > ${p7b_filename}.crt
使用方法sh p7b_to_crt.sh p7b文件
code
實際用例sh p7b_to_crt.sh owner1a_520wdy_com.p7b
blog
生成的crt在當前目錄下,與p7b文件同名。ssl