Recently in the configuration of HTTPS work order, encountered two customer-provided CRT nonstandard, need to manually from the p7b file to Base64 encoding according to P7B and CRT files to export the certificate one by one, stitching into a new CRT, the process is more cumbersome. To improve efficiency, online queries have found a way to convert the CRT using commands, in the following steps:
Take the 1.A.COM.P7B certificate as an example and convert to 1.A.COM.CRT
- To run the fold command conversion format
fold -w 64 1.a.com.p7b > temp.p7b
- Convert p7b to CRT using OpenSSL
openssl pkcs7 -print_certs -in temp.p7b |grep -Ev ‘^\s*$|subject|issuer‘ > 1.a.com.crt
corresponding script
#!/bin/bashp7b_file="$1"p7b_filename=$(echo ${p7b_file} |sed -r ‘s#(.*).p7b#\1#g‘)usage (){ echo "Usage:sh $0 p7b_file" exit 0}[ $# -ne 1 ] && usagefold -w 64 ${p7b_file} > temp.p7bopenssl pkcs7 -print_certs -in temp.p7b |grep -Ev ‘^\s*$|subject|issuer‘ > ${p7b_filename}.crt
- How to use
sh p7b_to_crt.sh p7b文件
- Actual Use Cases
sh p7b_to_crt.sh owner1a_520wdy_com.p7b
The generated CRT is in the current directory with the same name as the p7b file.
HTTPS-P7B Certificate Conversion