openssl 常用命令 pkcs12

openssl pkcs12

openssl pkcs12 官方文档

1. 描述

The pkcs12 command allows PKCS#12 files (sometimes referred to as PFX files) to be created and parsed. PKCS#12 files are used by several programs including Netscape, MSIE and MS Outlook.

pkcs12 命令是用来创建或者解析 PKCS12 格式(有时候也称PFX格式)的文件。

pkcs12 格式文件用于 Netscape, MSIE, MS Outlook等服务器。

pkcs12 格式的文件,可以理解为证书+私钥,即 cert+key。

2. 常用命令

解析命令

shell 复制代码
# 查看证书信息 -info
openssl pkcs12 -in server.p12 -info
# 不打印私钥和证书内容 -noout
openssl pkcs12 -in server.p12 -noout
# 只输出客户端证书(不包含CA证书) -clerts
openssl pkcs12 -in server.p12 -clcerts
# 只输出CA证书(不包含客户端证书) -cacerts
openssl pkcs12 -in server.p12 -cacerts
# 不输出证书 -nocerts
openssl pkcs12 -in server.p12 -nocerts
# 不输出私钥 -nokeys
openssl pkcs12 -in server.p12 -nokeys
# 不加密私钥 -nodes
openssl pkcs12 -in server.p12 -nodes

创建命令

shell 复制代码
# 创建 -export
# 前提 已获得 私钥文件 server.key和证书文件 server.crt(可以用下边命令生成)
# 使用 genpkey 生成 server.key
openssl genpkey -aes256 -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out server.key
# 使用 req 命令生成 server.crt 文件
openssl req -x509 -new -sha256 -days 3650 -key server.key -out server.crt -subj "/C=CN/test123"

# 创建 server.p12 -export(需要交互式输入server.key的口令,以及输出的server.p12的口令)
openssl pkcs12 -inkey server.key -in server.crt -export -out server.p12

# 提取PEM文件(含私钥)
openssl pkcs12 -in server.p12 -out server.pem
# 仅提取私钥并设置私钥口令,默认为 des3 加密算法
openssl pkcs12 -nocerts -in server.p12 -out server.key
# 仅提取私钥并设置私钥口令,指定 -aes256 加密算法
openssl pkcs12 -nocerts -in server.p12 -aes256 -out server.key
# 仅提取私钥并不设置私钥口令
openssl pkcs12 -nocerts -nodes -in server.p12 -out server.key
# 检查私钥
openssl rsa -in server.key -check
# 仅提取证书(所有证书)
openssl pkcs12 -nokeys -in server.p12 -out server.crt
# 仅提取CA证书
openssl pkcs12 -nokeys -cacerts -in server.p12 -out cacert.crt
# 仅提取server证书
openssl pkcs12 -nokeys -clcerts -in server.p12 -out server.crt

3. 命令选项

参考官方文档:

openssl pkcs12 官方文档

相关推荐
waving-black19 分钟前
利用frp和腾讯云服务器将内网暴露至外网(内网穿透)
linux·服务器·腾讯云·frp·内网穿透
stormsha31 分钟前
Linux中su与sudo命令的区别:权限管理的关键差异解析
linux·运维·服务器·鸿蒙系统·ux·batch命令
新加坡内哥谈技术1 小时前
Meta计划借助AI实现广告创作全自动化
运维·人工智能·自动化
zyjyyds1131 小时前
win11系统 Docker Desktop 突然提示Docker Engine stopped解决情况之一
运维·docker·容器
Altairr1 小时前
Docker基础(一)
运维·docker·容器·eureka
筏.k1 小时前
grep、wc 与管道符快速上手指南
linux
文牧之1 小时前
PostgreSQL 的扩展pageinspect
运维·数据库·postgresql
Johny_Zhao2 小时前
华为MAAS、阿里云PAI、亚马逊AWS SageMaker、微软Azure ML各大模型深度分析对比
linux·人工智能·ai·信息安全·云计算·系统运维
CodeOfCC2 小时前
c语言 封装跨平台线程头文件
linux·c语言·windows
科文小白狼2 小时前
Linux下VSCode开发环境配置(LSP)
linux·vscode·里氏替换原则·lsp