在 Linux 上,可以通过 keytool
、openssl
和 gskcmd
查看不同类型的证书文件(.jks
、.kdb
、.crt
、.cer
、.pem
、 .p12
)中证书的详细信息。
1. 查看 .jks
文件
使用 keytool
keytool -list -v -keystore yourfile.jks
查看特定别名的条目
keytool -list -v -keystore yourfile.jks -alias alias_name
用法:
keytool -list -v -keystore mykeystore.jks -storepass mypassword
2. 查看 .kdb
文件
使用 gskcmd
IBM 提供的 gskcmd
工具用于管理 .kdb
文件。
查看 .kdb
文件内容
gskcmd -cert -list -db yourfile.kdb -pw password
查看特定证书详细信息
gskcmd -cert -details -db yourfile.kdb -label "cert_label" -pw password
用法:
gskcmd -cert -list -db mykeystore.kdb -pw mypassword
注意:
gskcmd
通常随 IBM MQ 或 WebSphere 安装,需将其路径加入环境变量。
3. 查看 .crt
和 .cer
文件
使用 openssl
openssl x509 -in yourfile.crt -text -noout
用法:
openssl x509 -in certificate.crt -text -noout
4. 查看 .pem
文件
使用 openssl
openssl x509 -in yourfile.pem -text -noout
查看私钥(如果包含在 .pem
文件中)
openssl rsa -in yourfile.pem -text -noout
用法:
openssl x509 -in cert.pem -text -noout
openssl rsa -in key.pem -text -noout
5. 查看 .p12
文件
使用 openssl
openssl pkcs12 -in yourfile.p12 -info -nokeys
查看私钥
openssl pkcs12 -in yourfile.p12 -nocerts -info
用法:
openssl pkcs12 -in mycert.p12 -info -nokeys
总结命令对照表
文件类型 | 工具 | 命令 |
---|---|---|
.jks | keytool | keytool -list -v -keystore yourfile.jks |
.kdb | gskcmd | gskcmd -cert -list -db yourfile.kdb -pw password |
.crt | openssl | openssl x509 -in yourfile.crt -text -noout |
.cer | openssl | openssl x509 -in yourfile.cer -text -noout |
.pem | openssl | openssl x509 -in yourfile.pem -text -noout |
.p12 | openssl | openssl pkcs12 -in yourfile.p12 -info -nokeys |
注意事项
-
权限问题:
确保对证书文件有足够权限:chmod 600 yourfile.*
-
工具路径:
确保keytool
、openssl
和gskcmd
在 PATH 环境变量中。 -
安装
openssl
:
如果未安装,可通过以下命令安装:sudo apt install openssl # Debian/Ubuntu sudo yum install openssl # CentOS/RHEL