版本:2.1.8
易加密小工具 - 常用密码学操作命令行工具,支持 AES、SM4、RSA、ECC、SM2、ZUC、哈希、HMAC、证书解析等。


目录

  1. 快速入门
  2. 主命令与全局帮助
  3. version - 版本信息
  4. aes - AES 加解密
  5. sm4 - SM4 国密加解密
  6. random-str - 随机字符串生成
  7. hash - 哈希摘要
  8. hmac - HMAC 消息验证码
  9. rsa - RSA 加解密与签名验签
  10. ecc - ECC 签名验签与密钥交换
  11. sm2 - SM2 国密加解密与签名验签
  12. zuc - ZUC 祖冲之流密码
  13. cert-parse - 证书解析

1. 快速入门

1.1 安装与调用

1
2
3
# 安装后可通过以下方式调用
pip install easy-encryption-tool\[gmssl\] --upgrade
easy_encryption_tool --help

QQ_1771313662527

1.2 常用示例

QQ_1771313686045

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# AES 加密
easy_encryption_tool aes -a encrypt -i 'hello'

# 生成 32 位随机串
easy_encryption_tool random-str -l 32

# SHA256 哈希
easy_encryption_tool hash -i 'data' -a sha256

# 查看版本
easy_encryption_tool version

2. 主命令与全局帮助

2.1 主命令

命令说明
easy_encryption_tool主入口,无子命令时显示引导提示
easy_encryption_tool --help显示所有子命令列表

2.2 示例

1
2
# 显示主帮助
easy_encryption_tool --help

说明:直接运行 easy_encryption_tool 会显示常用命令示例;带 --help 会列出所有子命令。


3. version - 版本信息

3.1 功能说明

展示当前工具版本、Python 版本、操作系统、处理器架构、字节序及 CipherHUB 官网信息。

QQ_1771313734303

3.2 命令格式

1
easy_encryption_tool version

3.3 参数说明

本命令无参数。

3.4 示例

1
easy_encryption_tool version

输出示例

1
2
3
4
5
6
7
tool-version:v2.0.7
python:3.12.x
os:darwin
chip:...
byte-order:little
website:https://cipherhub.cloud
tagline:Serious Cryptography · Creative Solutions · Mapping Digital Trust

4. aes - AES 加解密

4.1 功能说明

AES 对称加解密工具,支持 AES-CBC-256AES-GCM-256 模式。加密输出为 Base64 编码;解密支持 Base64 密文或文件。与 CipherHUB 默认参数兼容。

QQ_1771313848957

QQ_1771313789415

4.2 命令格式

1
easy_encryption_tool aes [OPTIONS] -i INPUT_DATA

4.3 参数说明

参数短选项类型必填默认值说明
--mode-mchoicecbcAES 模式:cbcgcm
--key-kstring32 字节默认密钥,256 位;不足补齐、超出截取
--iv-nonce-vstring16/12 字节默认CBC 下 IV 16 字节,GCM 下 nonce 12 字节
--aad-stringCipherHUB 默认GCM 模式关联认证数据 AAD
--random-key-iv-rflagFalse自动生成随机密钥和 IV/nonce
--action-achoiceencrypt操作:encryptdecrypt
--input-data-istring-输入数据:明文/密文/文件路径
--is-base64-encoded-eflagFalse输入为 Base64 编码(与 -f 互斥)
--is-a-file-fflagFalse输入为文件路径(与 -e 互斥)
--input-limit-lint1非文件时最大输入长度(MB)
--output-file-ostring-输出文件路径,文件输入时必须指定
--no-force-flagFalse不覆盖已存在的输出文件
--gcm-pad-flagFalse[仅 GCM 模式] 加密前对明文做 PKCS#7 填充、解密后去除填充。默认不填充,与 CipherHUB stream_cipher 兼容;加密/解密需一致使用

4.4 GCM 模式与填充说明

  • CBC 模式:始终对明文做 PKCS#7 填充(块密码要求)。
  • GCM 模式:默认对明文做 PKCS#7 填充,直接加密原始数据,与 CipherHUB stream_cipher 行为一致。
  • 若需 GCM 模式下使用 PKCS#7 填充(例如与某些旧实现兼容),请加 --gcm-pad加密与解密必须同时使用或同时不使用 --gcm-pad,否则解密会失败。

4.5 输入数据约定

  • 默认-i 为 UTF-8 明文字符串
  • -e-i 为 Base64 编码数据
  • -f-i 为文件路径;此时必须指定 -o

4.6 示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 使用默认 CBC 模式加密明文字符串
easy_encryption_tool aes -a encrypt -i 'hello'

# 使用 GCM 模式加密(默认无填充,与 CipherHUB 兼容)
easy_encryption_tool aes -m gcm -a encrypt -i 'hello'

# GCM 模式启用 PKCS#7 填充(加密与解密需一致使用 --gcm-pad)
easy_encryption_tool aes -m gcm -a encrypt -i 'hello' --gcm-pad

# 使用随机密钥和 IV 加密
easy_encryption_tool aes -r -a encrypt -i 'hello'

# 解密 Base64 密文(需先加 -e 表示密文为 Base64)
easy_encryption_tool aes -a decrypt -i 'BASE64_CIPHER_STRING' -e

# 加密文件并输出到指定文件
easy_encryption_tool aes -a encrypt -i /path/to/input.txt -f -o /path/to/output.bin

# 解密文件
easy_encryption_tool aes -a decrypt -i /path/to/cipher.bin -f -o /path/to/plain.txt -e

# 不覆盖已存在的输出文件
easy_encryption_tool aes -a encrypt -i 'data' -o out.bin --no-force

5. sm4 - SM4 国密加解密

5.1 功能说明

SM4 国密对称加解密,支持 SM4-CBCSM4-GCM 模式。需安装 easy_gmssl 依赖。

QQ_1771313878002

QQ_1771313828594

5.2 命令格式

1
easy_encryption_tool sm4 [OPTIONS] -i INPUT_DATA

5.3 参数说明

参数短选项类型必填默认值说明
--mode-mchoicecbc模式:cbcgcm
--key-kstring16 字节默认密钥 16 字节
--iv-nonce-vstring16/12 字节默认CBC 下 IV 16 字节,GCM 下 nonce 12 字节
--aad-stringCipherHUB 默认GCM 模式 AAD
--random-key-iv-rflagFalse随机生成密钥和 IV/nonce
--action-achoiceencryptencryptdecrypt
--input-data-istring-输入数据
--is-base64-encoded-eflagFalse输入为 Base64
--is-a-file-fflagFalse输入为文件
--input-limit-lint1非文件时最大输入(MB)
--output-file-ostring-文件输入时必须指定
--no-force-flagFalse不覆盖已存在输出文件
--gcm-pad-flagFalse[仅 GCM 模式] 加密前对明文做 PKCS#7 填充、解密后去除填充。默认不填充;加密/解密需一致使用

5.4 GCM 模式与填充说明

  • CBC 模式:始终对明文做 PKCS#7 填充。
  • GCM 模式:默认对明文做 PKCS#7 填充,与 CipherHUB stream_cipher 兼容。若需填充,使用 --gcm-pad,加密与解密必须一致。

5.5 示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# SM4-CBC 加密
easy_encryption_tool sm4 -a encrypt -i '你好'

# SM4-GCM 加密(默认无填充)
easy_encryption_tool sm4 -m gcm -a encrypt -i 'hello'

# SM4-GCM 启用 PKCS#7 填充
easy_encryption_tool sm4 -m gcm -a encrypt -i 'hello' --gcm-pad

# 随机密钥加密
easy_encryption_tool sm4 -r -a encrypt -i 'data'

# 解密 Base64 密文
easy_encryption_tool sm4 -a decrypt -i 'BASE64_CIPHER' -e

# 文件加解密
easy_encryption_tool sm4 -a encrypt -i input.txt -f -o cipher.bin
easy_encryption_tool sm4 -a decrypt -i cipher.bin -f -o plain.txt -e

6. random-str - 随机字符串生成

6.1 功能说明

使用密码学安全随机数(CSPRNG)生成随机字符串,可用于密钥、IV、令牌等。

QQ_1771313922968

6.2 命令格式

1
easy_encryption_tool random-str [OPTIONS]

6.3 参数说明

参数短选项类型必填默认值说明
--length-lint32生成字符串长度(1 至系统最大整型)
--output-file-ostring-输出到文件
--no-force-flagFalse不覆盖已存在输出文件

6.4 示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 生成 32 位随机串(默认)
easy_encryption_tool random-str

# 生成 64 位随机串
easy_encryption_tool random-str -l 64

# 生成 16 位随机串
easy_encryption_tool random-str -l 16

# 输出到文件
easy_encryption_tool random-str -l 32 -o random_key.txt

# 不覆盖已有文件
easy_encryption_tool random-str -l 32 -o key.txt --no-force

7. hash - 哈希摘要

7.1 功能说明

计算哈希摘要,支持 SM3SHA256SHA384SHA512。SM3 需 easy_gmssl

QQ_1771313958784

7.2 命令格式

1
easy_encryption_tool hash [OPTIONS] -i INPUT_DATA

7.3 参数说明

参数短选项类型必填默认值说明
--input-data-istring-输入:字符串、Base64 或文件路径
--is-base64-encoded-eflagFalse输入为 Base64(与 -f 互斥)
--is-a-file-fflagFalse输入为文件路径(与 -e 互斥)
--hash-alg-achoicesha256算法:sm3sha256sha384sha512

7.4 示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# SHA256 哈希(默认)
easy_encryption_tool hash -i 'hello'

# SM3 哈希
easy_encryption_tool hash -i 'hello' -a sm3

# SHA384 哈希
easy_encryption_tool hash -i 'data' -a sha384

# 对 Base64 编码数据哈希
easy_encryption_tool hash -i 'aGVsbG8=' -e -a sha256

# 对文件计算哈希
easy_encryption_tool hash -i /path/to/file.bin -f -a sha256

8. hmac - HMAC 消息验证码

8.1 功能说明

计算 HMAC 消息验证码,支持 SM3、SHA224、SHA256、SHA384、SHA512、SHA3 系列。SM3 需 easy_gmssl

QQ_1771313995758

8.2 命令格式

1
easy_encryption_tool hmac [OPTIONS] -i INPUT_DATA

8.3 参数说明

参数短选项类型必填默认值说明
--input-data-istring-输入数据
--is-base64-encoded-eflagFalse输入为 Base64
--is-a-file-fflagFalse输入为文件
--hash-alg-achoicesha256哈希算法
--key-kstring32 字节默认HMAC 密钥
--random-key-rflagFalse自动生成 32 字节随机密钥

8.4 示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 使用默认 SHA256 和默认密钥
easy_encryption_tool hmac -i 'hello'

# 指定密钥和 SM3
easy_encryption_tool hmac -i 'data' -k 'my_secret_key_32_bytes_long!!!!' -a sm3

# 随机密钥
easy_encryption_tool hmac -i 'hello' -r

# 对文件计算 HMAC
easy_encryption_tool hmac -i /path/to/file -f -a sha256

9. rsa - RSA 加解密与签名验签

QQ_1771314036092

9.1 子命令概览

子命令说明
generate生成 RSA 密钥对
encrypt公钥加密
decrypt私钥解密
sign私钥签名
verify公钥验签

9.2 rsa generate - 生成密钥对

命令格式

1
easy_encryption_tool rsa generate [OPTIONS]

参数说明

参数短选项类型必填默认值说明
--size-schoice2048密钥位数:204830724096
--encoding-echoicepem格式:pemder
--file-name-fstringdemo输出文件名前缀
--password-pstring-私钥密码
--random-password-rflagFalse生成 32 字节随机私钥密码

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 生成 2048 位 RSA 密钥对,输出 demo_rsa_public.pem / demo_rsa_private.pem
easy_encryption_tool rsa generate -f demo

# 生成 4096 位密钥对
easy_encryption_tool rsa generate -s 4096 -f my_rsa

# 带密码保护
easy_encryption_tool rsa generate -f demo -p 'my_password'

# 随机密码
easy_encryption_tool rsa generate -f demo -r

9.3 rsa encrypt - 公钥加密

参数说明

参数短选项类型必填默认值说明
--public-key-fstring-公钥文件路径
--input-data-istring-明文(字符串或 Base64)
--encoding-echoicepem密钥格式
--b64-encoded-cflagFalse输入为 Base64
--input-limit-lint1最大输入长度(MB)
--mode-mchoiceoaep填充:oaeppkcs1v15
--hash-mode-hchoicesha256OAEP 时哈希:sha1/sha224/sha256/sha384/sha512

示例

1
2
3
4
5
6
7
8
# 使用 OAEP+SHA256 加密
easy_encryption_tool rsa encrypt -f demo_rsa_public.pem -i 'hello'

# 使用 PKCS1v15
easy_encryption_tool rsa encrypt -f pub.pem -i 'data' -m pkcs1v15

# 输入为 Base64
easy_encryption_tool rsa encrypt -f pub.pem -i 'aGVsbG8=' -c

9.4 rsa decrypt - 私钥解密

参数说明

参数短选项类型必填默认值说明
--private-key-fstring-私钥文件路径
--input-data-istring-Base64 密文
--encoding-echoicepem密钥格式
--mode-mchoiceoaep填充模式
--hash-mode-hchoicesha256OAEP 哈希
--password-pstring-私钥密码

示例

1
2
3
4
5
# 解密
easy_encryption_tool rsa decrypt -f demo_rsa_private.pem -i 'BASE64_CIPHER'

# 带密码
easy_encryption_tool rsa decrypt -f pri.pem -i 'CIPHER' -p 'my_password'

9.5 rsa sign - 私钥签名

参数说明

参数短选项类型必填默认值说明
--private-key-fstring-私钥文件路径
--input-data-istring-待签名数据
--encoding-echoicepem密钥格式
--mode-mchoicepss填充:psspkcs1v15
--hash-mode-hchoicesha256哈希算法
--password-pstring-私钥密码
--b64-encoded-cflagFalse输入为 Base64
--input-is-digest-dflagFalse输入为预计算摘要

示例

1
2
3
4
5
6
7
8
# PSS 签名
easy_encryption_tool rsa sign -f pri.pem -i 'hello' -m pss

# PKCS1v15 签名
easy_encryption_tool rsa sign -f pri.pem -i 'data' -m pkcs1v15

# 对摘要签名
easy_encryption_tool rsa sign -f pri.pem -i 'HEX_DIGEST_32_BYTES' -d -h sha256

9.6 rsa verify - 公钥验签

参数说明

参数短选项类型必填默认值说明
--public-key-fstring-公钥文件路径
--input-data-istring-被验签数据
--signature-sstring-Base64 签名值
--encoding-echoicepem密钥格式
--mode-mchoicepss填充模式
--hash-mode-hchoicesha256哈希算法
--b64-encoded-cflagFalse输入为 Base64
--input-is-digest-dflagFalse输入为预计算摘要

示例

1
2
# 验签
easy_encryption_tool rsa verify -f pub.pem -i 'hello' -s 'BASE64_SIGNATURE' -m pss

10. ecc - ECC 签名验签与密钥交换

QQ_1771314073342

10.1 子命令概览

子命令说明
generate生成 ECC 密钥对
ecdhECDH 密钥交换
signECC 签名
verifyECC 验签

10.2 ecc generate - 生成密钥对

参数说明

参数短选项类型必填默认值说明
--curve-cchoicesecp256k1曲线:secp256r1/secp384r1/secp521r1/secp256k1
--encoding-echoicepem格式:pem/der
--file-name-fstringdemo输出文件名前缀
--password-pstring-私钥密码
--random-password-rflagFalse随机私钥密码

示例

1
2
3
4
5
# 生成 secp256k1 密钥对
easy_encryption_tool ecc generate -f demo

# 指定曲线
easy_encryption_tool ecc generate -c secp256r1 -f alice

10.3 ecc ecdh - 密钥交换

参数说明

参数短选项类型必填默认值说明
--alice-pub-key-astring-己方公钥路径
--alice-pri-key-kstring-己方私钥路径
--bob-pub-key-bstring-对方公钥路径
--password-pstring-己方私钥密码
--encoding-echoicepem密钥格式
--length-lint32派生密钥长度(16-64)
--hash-mode-hchoicesha512HKDF 哈希
--salt-sstringCipherHUB 默认HKDF 盐值
--context-cstringCipherHUB 默认HKDF 附加信息

示例

1
2
3
4
5
# 执行 ECDH 密钥交换
easy_encryption_tool ecc ecdh -a alice_public.pem -k alice_private.pem -b bob_public.pem

# 带私钥密码
easy_encryption_tool ecc ecdh -a alice_pub.pem -k alice_pri.pem -b bob_pub.pem -p 'password'

10.4 ecc sign / ecc verify

参数说明(sign)

参数短选项类型必填默认值说明
--private-key-fstring-私钥路径
--input-data-istring-待签名数据
--encoding-echoicepem密钥格式
--hash-mode-hchoicesha512哈希算法
--password-pstring-私钥密码
--b64-encoded-cflagFalse输入为 Base64
--input-is-digest-dflagFalse输入为预计算摘要

参数说明(verify)

参数短选项类型必填默认值说明
--public-key-fstring-公钥路径
--input-data-istring-被验签数据
--signature-sstring-Base64 签名
其他----同 sign

示例

1
2
3
4
5
# 签名
easy_encryption_tool ecc sign -f pri.pem -i 'hello'

# 验签
easy_encryption_tool ecc verify -f pub.pem -i 'hello' -s 'BASE64_SIG'

11. sm2 - SM2 国密加解密与签名验签

QQ_1771314104955

需安装 easy_gmssl

11.1 子命令概览

子命令说明
generate生成 SM2 密钥对
encrypt公钥加密
decrypt私钥解密
sign私钥签名
verify公钥验签

11.2 sm2 generate

参数说明

参数短选项类型必填默认值说明
--file-name-fstringdemo输出文件名前缀
--password-pstring-私钥密码(1-32 字节,必填或使用 -r
--random-password-rflagFalse生成 32 字节随机密码

示例

1
2
3
4
5
# 生成 SM2 密钥对(必须指定密码或 -r)
easy_encryption_tool sm2 generate -f demo -p '12345678'

# 随机密码
easy_encryption_tool sm2 generate -f demo -r

11.3 sm2 encrypt

参数说明

参数短选项类型必填默认值说明
--public-key-fstring-公钥文件路径
--input-data-istring-明文
--b64-encoded-cflagFalse输入为 Base64
--cipher-mode-mchoiceC1C3C2_ASN1密文格式:C1C3C2_ASN1/C1C3C2/C1C2C3_ASN1/C1C2C3
--output-format-ochoicebase64输出:base64 或 hex
--input-limit-lint1最大输入(MB)

示例

1
easy_encryption_tool sm2 encrypt -f demo_sm2_public.pem -i 'hello'

11.4 sm2 decrypt

参数说明

参数短选项类型必填默认值说明
--private-key-fstring-私钥路径
--input-data-istring-密文(Base64 或 hex)
--hex-input-xflagFalse输入为 hex
--cipher-mode-mchoiceC1C3C2_ASN1密文格式
--password-pstring-私钥密码

示例

1
easy_encryption_tool sm2 decrypt -f demo_sm2_private.pem -i 'BASE64_CIPHER' -p '12345678'

11.5 sm2 sign

参数说明

参数短选项类型必填默认值说明
--private-key-fstring-私钥路径
--input-data-istring-待签名数据
--b64-encoded-cflagFalse输入为 Base64
--input-is-digest-dflagFalse输入为 SM3 摘要(32 字节)
--signature-mode-mchoiceRS_ASN1签名格式:RS_ASN1 或 RS
--password-pstring-私钥密码
--signer-id-string1234567812345678SM2 用户标识

示例

1
easy_encryption_tool sm2 sign -f pri.pem -i 'hello' -p 'password'

11.6 sm2 verify

参数说明

参数短选项类型必填默认值说明
--public-key-fstring-公钥路径
--input-data-istring-被验签数据
--signature-sstring-签名(Base64 或 hex)
--sig-b64 / --sig-hex-flag-sig-b64签名编码格式
其他----同 sign

示例

1
easy_encryption_tool sm2 verify -f pub.pem -i 'hello' -s 'BASE64_SIG' -p 'password'

12. zuc - ZUC 祖冲之流密码

QQ_1771314128990

12.1 功能说明

ZUC 流密码加解密,密钥和 IV 均为 16 字节。密文与明文等长。需 easy_gmssl

12.2 命令格式

1
easy_encryption_tool zuc [OPTIONS] -i INPUT_DATA

12.3 参数说明

参数短选项类型必填默认值说明
--key-kstring16 字节默认密钥
--iv-vstring16 字节默认IV
--random-key-iv-rflagFalse随机生成密钥和 IV
--action-achoiceencryptencrypt 或 decrypt
--input-data-istring-输入数据
--is-base64-encoded-eflagFalse输入为 Base64
--is-a-file-fflagFalse输入为文件
--input-limit-lint1非文件时最大输入(MB)
--output-file-ostring-文件输入时必须指定
--no-force-flagFalse不覆盖已存在输出

12.4 示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 加密
easy_encryption_tool zuc -a encrypt -i 'hello'

# 随机密钥加密
easy_encryption_tool zuc -r -a encrypt -i 'data'

# 解密
easy_encryption_tool zuc -a decrypt -i 'BASE64_CIPHER' -e

# 文件加解密
easy_encryption_tool zuc -a encrypt -i input.bin -f -o output.bin

13. cert-parse - 证书解析

QQ_1771314146943

13.1 功能说明

解析 PEM 或 DER 格式的 X.509 证书,支持国际算法及国密 SM2 证书。可验证证书签名(通过 AIA 获取 CA)。

13.2 命令格式

1
easy_encryption_tool cert-parse [OPTIONS] -f CERT_FILE

13.3 参数说明

参数短选项类型必填默认值说明
--cert-file-fstring-证书文件路径
--encoding-echoicepem格式:pem 或 der
--gm-cert-gflagFalse按国密 SM2 证书解析(仅 PEM)
--verbose-vflagFalse显示详细信息

13.4 示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 解析 PEM 证书
easy_encryption_tool cert-parse -f /path/to/cert.pem -e pem

# 解析 DER 证书
easy_encryption_tool cert-parse -f cert.der -e der

# 解析国密 SM2 证书
easy_encryption_tool cert-parse -f sm2_cert.pem -e pem -g

# 显示详细信息
easy_encryption_tool cert-parse -f cert.pem -e pem -v

附录 A:通用约定

A.1 输入数据标识

  • 默认-i 为 UTF-8 明文字符串
  • -e / --is-base64-encoded:输入为 Base64
  • -f / --is-a-file:输入为文件路径
    -e-f 互斥,不可同时使用。

A.2 文件操作

  • 输入为文件时,通常需指定 -o 输出文件
  • 默认会覆盖已存在输出文件;使用 --no-force 可禁止覆盖

A.3 国密算法依赖

SM2、SM3、SM4、ZUC 等国密算法需安装 easy_gmssl

1
pip install easy_gmssl

A.4 CipherHUB 兼容

工具默认参数与 CipherHUB 保持一致,便于与 Web/API 互操作。


附录 B:命令速查表

命令用途
version版本信息
aesAES-CBC/GCM 加解密
sm4SM4-CBC/GCM 加解密
random-str随机字符串
hash哈希摘要
hmacHMAC
rsa generate/encrypt/decrypt/sign/verifyRSA 操作
ecc generate/ecdh/sign/verifyECC 操作
sm2 generate/encrypt/decrypt/sign/verifySM2 操作
zucZUC 流密码
cert-parse证书解析