gmssl命令行怎么用
时间: 2023-07-03 17:27:42 浏览: 75
`gmssl` 是一个 OpenSSL 的分支,它的命令行使用方法与 OpenSSL 类似。下面是一些 `gmssl` 常用命令的用法示例:
1. 生成 RSA 密钥对:
```sh
gmssl genrsa -out private.pem 2048
```
这条命令会生成一个 2048 位的 RSA 密钥对,并将私钥保存到 `private.pem` 文件中。
2. 生成自签名证书:
```sh
gmssl req -new -x509 -key private.pem -out cert.pem -subj "/CN=example.com"
```
这条命令会使用 `private.pem` 中的私钥生成一个自签名证书,并将证书保存到 `cert.pem` 文件中。`-subj` 参数指定了证书的主题信息,这里将证书的 Common Name 设置为 `example.com`。
3. 查看 PEM 格式证书信息:
```sh
gmssl x509 -in cert.pem -text -noout
```
这条命令会输出 `cert.pem` 中的证书信息。
4. 查看 PKCS#12 格式证书信息:
```sh
gmssl pkcs12 -info -in cert.p12
```
这条命令会输出 `cert.p12` 中的证书和私钥信息。
5. 对称加密文件:
```sh
gmssl enc -aes-256-cbc -in plaintext.txt -out ciphertext.enc -pass pass:password
```
这条命令会使用 AES-256-CBC 算法对 `plaintext.txt` 文件进行加密,并将加密后的结果保存到 `ciphertext.enc` 文件中。`-pass` 参数指定了密码,这里使用了明文密码 `password`。
6. 对称解密文件:
```sh
gmssl enc -d -aes-256-cbc -in ciphertext.enc -out plaintext.txt -pass pass:password
```
这条命令会使用 AES-256-CBC 算法对 `ciphertext.enc` 文件进行解密,并将解密后的结果保存到 `plaintext.txt` 文件中。`-d` 参数指定了解密操作,`-pass` 参数指定了密码,这里使用了与加密时相同的明文密码 `password`。
以上是一些 `gmssl` 常用命令的示例,更多命令和选项可以查看 `gmssl` 的帮助文档。