前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >OpenSSL 常用命令

OpenSSL 常用命令

作者头像
雨落秋垣
发布2024-10-30 23:31:32
880
发布2024-10-30 23:31:32
举报
文章被收录于专栏:雨落秋垣

查看证书信息

代码语言:txt
复制
openssl x509 -noout -text -in _.httpsok.com.pem

查看 KEY 信息

RSA

代码语言:txt
复制
openssl rsa -noout -text -in _.httpsok.com.pem

ECC

代码语言:txt
复制
openssl ec -noout -text -in _.httpsok.com.pem

测试证书

代码语言:txt
复制
openssl s_client -connect httpsok.com:443

常见证书格式

  • PEM(.pem) nginx 默认
  • DER(.cer .der) Windows 上常见
  • PKCS#12文件(.pfx .p12) IIS、Tomcat、Mac 上常见

证书格式转换

PEM转换为DER

代码语言:txt
复制
openssl x509 -outform der -in _.httpsok.com.pem -out _.httpsok.com.der

DER转换为PEM

代码语言:txt
复制
# 会导致证书链丢失
openssl x509 -inform der -in _.httpsok.com.der -out _.httpsok.com.pem

PEM转换为PKCS

代码语言:txt
复制
# 密码:12345678
openssl pkcs12 -export -out httpsok.com.pfx -inkey _.httpsok.com.key -in _.httpsok.com.pem -passout pass:12345678

PKCS转换为PEM

代码语言:txt
复制
# 会增加一些证书冗余信息
openssl pkcs12 -in httpsok.com.pfx -out httpsok.com.pem -nodes

启用老算法(遗留算法)

修改文件

代码语言:txt
复制
vim /etc/ssl/openssl.cnf

内容

代码语言:txt
复制
openssl_conf = openssl_init

[openssl_init]
providers = provider_sect

[provider_sect]
default = default_sect
legacy = legacy_sect

[default_sect]
activate = 1

[legacy_sect]
activate = 1

PEM转PKCS12详解

需要先启用遗留算法

转换命令(兼容性好)

代码语言:txt
复制
openssl pkcs12 -export \
  -out cert.pfx \
  -inkey cert.key \
  -in cert.pem \
  -passout pass:123456 \
  -name "httpsok.com" \
  -certpbe PBE-SHA1-RC2-40 \
  -keypbe PBE-SHA1-3DES \
  -macalg sha1

转换命令(3.0默认)

代码语言:txt
复制
openssl pkcs12 -export \
  -out cert.pfx \
  -inkey cert.key \
  -in cert.pem \
  -passout pass:123456 \
  -name "httpsok.com"

查看详情

代码语言:txt
复制
openssl pkcs12 -info -in cert.pfx -passin pass:123456 -noout

详情内容

代码语言:txt
复制
MAC: sha1, Iteration 2048
MAC length: 20, salt length: 8
PKCS7 Encrypted data: pbeWithSHA1And40BitRC2-CBC, Iteration 2048
Certificate bag
Certificate bag
Certificate bag
PKCS7 Data
Shrouded Keybag: pbeWithSHA1And3-KeyTripleDES-CBC, Iteration 2048

帮助文档

代码语言:txt
复制
openssl pkcs12  -help
Usage: pkcs12 [options]

General options:
 -help               Display this summary
 -in infile          Input file
 -out outfile        Output file
 -passin val         Input file pass phrase source
 -passout val        Output file pass phrase source
 -password val       Set PKCS#12 import/export password source
 -twopass            Separate MAC, encryption passwords
 -nokeys             Don't output private keys
 -nocerts            Don't output certificates
 -noout              Don't output anything, just verify PKCS#12 input
 -legacy             Use legacy encryption: 3DES_CBC for keys, RC2_CBC for certs
 -engine val         Use engine, possibly a hardware device

Provider options:
 -provider-path val  Provider load path (must be before 'provider' argument if required)
 -provider val       Provider to load (can be specified multiple times)
 -propquery val      Property query used when fetching algorithms

Random state options:
 -rand val           Load the given file(s) into the random number generator
 -writerand outfile  Write random data to the specified file

PKCS#12 import (parsing PKCS#12) options:
 -info               Print info about PKCS#12 structure
 -nomacver           Don't verify integrity MAC
 -clcerts            Only output client certificates
 -cacerts            Only output CA certificates
 -*                  Any supported cipher for output encryption
 -noenc              Don't encrypt private keys
 -nodes              Don't encrypt private keys; deprecated

PKCS#12 output (export) options:
 -export             Create PKCS12 file
 -inkey val          Private key, else read from -in input file
 -certfile infile    Extra certificates for PKCS12 output
 -passcerts val      Certificate file pass phrase source
 -chain              Build and add certificate chain for EE cert,
                     which is the 1st cert from -in matching the private key (if given)
 -untrusted infile   Untrusted certificates for chain building
 -CAfile infile      PEM-format file of CA's
 -CApath dir         PEM-format directory of CA's
 -CAstore uri        URI to store of CA's
 -no-CAfile          Do not load the default certificates file
 -no-CApath          Do not load certificates from the default certificates directory
 -no-CAstore         Do not load certificates from the default certificates store
 -name val           Use name as friendly name
 -caname val         Use name as CA friendly name (can be repeated)
 -CSP val            Microsoft CSP name
 -LMK                Add local machine keyset attribute to private key
 -keyex              Set key type to MS key exchange
 -keysig             Set key type to MS key signature
 -keypbe val         Private key PBE algorithm (default AES-256 CBC)
 -certpbe val        Certificate PBE algorithm (default PBES2 with PBKDF2 and AES-256 CBC)
 -descert            Encrypt output with 3DES (default PBES2 with PBKDF2 and AES-256 CBC)
 -macalg val         Digest algorithm to use in MAC (default SHA1)
 -iter +int          Specify the iteration count for encryption and MAC
 -noiter             Don't use encryption iteration
 -nomaciter          Don't use MAC iteration)
 -maciter            Unused, kept for backwards compatibility
 -nomac              Don't generate MAC

本文系外文翻译,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系外文翻译前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 查看证书信息
  • 查看 KEY 信息
    • RSA
      • ECC
      • 测试证书
      • 常见证书格式
      • 证书格式转换
        • PEM转换为DER
          • DER转换为PEM
            • PEM转换为PKCS
              • PKCS转换为PEM
              • 启用老算法(遗留算法)
                • 修改文件
                  • 内容
                  • PEM转PKCS12详解
                    • 转换命令(兼容性好)
                      • 转换命令(3.0默认)
                        • 查看详情
                          • 详情内容
                            • 帮助文档
                            领券
                            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档