本文档为 easy_encryption_tool 的完整 CLI 命令参考,适用于开发者文档、QA 测试用例生成及 CLI 可用性参考。



全局输出选项(适用于所有命令)
| 选项 | 说明 |
|---|---|
--json | 单行 JSON 输出,便于管道解析 |
--pretty-json | 显式指定彩色 pretty JSON(默认) |
--raw | 仅输出主结果值,便于复制/管道 |



一、对称加密
1.1 AES 命令
PURPOSE
对数据进行 AES-256 对称加密或解密。支持 CBC 和 GCM 两种模式。CBC 使用 PKCS#7 填充;GCM 默认无填充(CipherHUB 兼容),可选 --gcm-pad 启用 PKCS#7 填充。
BASIC USAGE
| |


VALID PARAMETER COMBINATIONS
| 组合 | 示例 |
|---|---|
| 文本加密(CBC 默认) | easy_encryption_tool aes -m cbc -A encrypt -i "hello" |
| 文本加密(GCM) | easy_encryption_tool aes -m gcm -A encrypt -i "hello" |
| 文本解密(base64 输入) | easy_encryption_tool aes -A decrypt -i "<cipher_b64>" -e |
| 文件加密 | easy_encryption_tool aes -A encrypt -i /path/to/file -f -o /path/to/out |
| 文件解密 | easy_encryption_tool aes -A decrypt -i /path/to/cipher -f -o /path/to/plain |
| 随机 key/iv | easy_encryption_tool aes -A encrypt -i "hello" -r |
| 自定义 key/iv | easy_encryption_tool aes -k "01234567890123456789012345678901" -v "0123456789012345" -A encrypt -i "hello" |
| GCM AAD | easy_encryption_tool aes -m gcm -A encrypt -i "hello" --aad "custom AAD" |
| GCM 填充 | easy_encryption_tool aes -m gcm -A encrypt -i "hello" --gcm-pad |
| JSON 输出 | easy_encryption_tool aes -A encrypt -i "hello" --json |
| Raw 输出 | easy_encryption_tool aes -A encrypt -i "hello" --raw |
| 提高输入限制 | easy_encryption_tool aes -A encrypt -i "..." -l 10 |
| 禁止覆盖输出文件 | easy_encryption_tool aes -A encrypt -i file -f -o out --no-force |
ADVANCED USAGE SCENARIOS
| |

INVALID INPUT EXAMPLES
| 命令 | 原因 | 预期错误 |
|---|---|---|
easy_encryption_tool aes -A encrypt | 缺少 -i | Error: Missing option '-i' / '--input-data' |
easy_encryption_tool aes -A decrypt -i "hello" | 解密需 base64 或文件,未加 -e | decrypt requires base64 cipher or file; use -e for base64 input |
easy_encryption_tool aes -i file -f -e | -e 与 -f 互斥 | cannot use -e and -f together |
easy_encryption_tool aes -i file -f | 文件输入需 -o | output file is required when input is a file |
easy_encryption_tool aes -A encrypt -i "..." -e 且输入非合法 base64 | 非法 base64 | invalid b64 encoded data |
easy_encryption_tool aes -m invalid -A encrypt -i "x" | 无效 mode | Click 选项错误 |
easy_encryption_tool aes -A encrypt -i "" | 空输入 | no input data, it is required |
MUTUALLY EXCLUSIVE PARAMETER CASES
-e与-f:不能同时指定。-e表示输入为 base64;-f表示输入为文件路径。-r与-k/-v:使用-r时,-k/-v会被覆盖为随机值。
EDGE CASES
| 场景 | 命令 | 预期行为 |
|---|---|---|
| 空输入 | easy_encryption_tool aes -A encrypt -i "" | 错误:no input data |
| 超长输入 | `easy_encryption_tool aes -A encrypt -i “$(head -c 2M /dev/zero | tr ‘\0’ ‘a’)"` |
| Unicode | easy_encryption_tool aes -A encrypt -i "你好世界" | 正常 UTF-8 编码 |
| 含换行 | easy_encryption_tool aes -A encrypt -i "line1\nline2" | 正常 |
| 二进制(base64) | `easy_encryption_tool aes -A encrypt -i “$(echo -n ‘\x00\x01’ | base64)” -e` |
OUTPUT STRUCTURE EXPECTATION
| |
1.2 SM4 命令
PURPOSE
国密 SM4 对称加密/解密。支持 CBC 和 GCM 模式。需安装 easy_gmssl。
BASIC USAGE
| |


VALID PARAMETER COMBINATIONS
| 组合 | 示例 |
|---|---|
| CBC 加密 | easy_encryption_tool sm4 -m cbc -A encrypt -i "hello" |
| GCM 加密 | easy_encryption_tool sm4 -m gcm -A encrypt -i "hello" |
| 解密 | easy_encryption_tool sm4 -A decrypt -i "<cipher>" -e |
| 文件 | easy_encryption_tool sm4 -A encrypt -i file -f -o out |
| 随机 key/iv | easy_encryption_tool sm4 -A encrypt -i "hello" -r |
| GCM AAD | easy_encryption_tool sm4 -m gcm -A encrypt -i "hello" --aad "AAD" |
--gcm-pad | easy_encryption_tool sm4 -m gcm -A encrypt -i "hello" --gcm-pad |
INVALID INPUT EXAMPLES
| 命令 | 原因 | 预期错误 |
|---|---|---|
| 未安装 easy_gmssl | 任意 sm4 命令 | 提示安装 easy_gmssl |
-e 与 -f 同时 | sm4 -i x -f -e | 互斥错误 |
| 解密无 base64 | sm4 -A decrypt -i "plain" | decrypt requires base64 cipher or file |
MUTUALLY EXCLUSIVE PARAMETER CASES
-e与-f:互斥。-r与-k/-v:-r时 key/iv 由工具生成。
EDGE CASES
| 场景 | 命令 | 预期 |
|---|---|---|
| 空输入 | sm4 -A encrypt -i "" | no input data |
| CBC 密文文件大小非 16 倍数 | sm4 -A decrypt -i bad.bin -f -o out | invalid cipher file size |
OUTPUT STRUCTURE EXPECTATION
| |
1.3 ZUC 命令
PURPOSE
国密 ZUC 流密码加密/解密。key 和 iv 均为 16 字节。需 easy_gmssl。
BASIC USAGE
| |

VALID PARAMETER COMBINATIONS
| 组合 | 示例 |
|---|---|
| 加密 | easy_encryption_tool zuc -A encrypt -i "hello" |
| 解密 | easy_encryption_tool zuc -A decrypt -i "<cipher>" -e |
| 文件 | easy_encryption_tool zuc -A encrypt -i file -f -o out |
| 随机 key/iv | easy_encryption_tool zuc -A encrypt -i "hello" -r |
| 自定义 key/iv | easy_encryption_tool zuc -k "0123456789012345" -v "0123456789012345" -A encrypt -i "x" |
ADVANCED USAGE SCENARIOS
| |
INVALID INPUT EXAMPLES
| 命令 | 原因 | 预期错误 |
|---|---|---|
| 未安装 easy_gmssl | 任意 zuc 命令 | 提示安装 |
| 解密无 base64 | zuc -A decrypt -i "plain" | decrypt requires base64 cipher or file |
文件输入无 -o | zuc -i file -f | output file is required for file input |
MUTUALLY EXCLUSIVE PARAMETER CASES
-e与-f:互斥。-r与-k/-v:-r时 key/iv 由工具生成。
EDGE CASES
| 场景 | 命令 | 预期 |
|---|---|---|
| 空输入 | zuc -A encrypt -i "" | no input data |
| 流密码密文长度=明文长度 | 正常 | 无填充,密文与明文等长 |
OUTPUT STRUCTURE EXPECTATION
| |
二、哈希
2.1 hash 命令
PURPOSE
计算消息摘要。支持 SHA256、SHA384、SHA512、SM3(需 easy_gmssl)。
BASIC USAGE
| |


VALID PARAMETER COMBINATIONS
| 组合 | 示例 |
|---|---|
| SHA256(默认) | easy_encryption_tool hash -i "hello" |
| SHA384 | easy_encryption_tool hash -i "hello" -a sha384 |
| SHA512 | easy_encryption_tool hash -i "hello" -a sha512 |
| SM3 | easy_encryption_tool hash -i "hello" -a sm3 |
| Base64 输入 | easy_encryption_tool hash -i "<b64>" -e |
| 文件输入 | easy_encryption_tool hash -i /path/to/file -f |
| JSON/Raw | easy_encryption_tool hash -i "hello" --json / --raw |
| stdin 间接输入 | echo "hello" | xargs -I {} easy_encryption_tool hash -i {} |
ADVANCED USAGE SCENARIOS
| |
INVALID INPUT EXAMPLES
| 命令 | 原因 | 预期错误 |
|---|---|---|
-e 与 -f 同时 | hash -i x -e -f | 互斥错误 |
| SM3 未安装 gmssl | hash -i "x" -a sm3 | 提示安装 easy_gmssl |
| 非法 base64 | hash -i "!!!" -e | invalid b64 encoded data |
| 无效算法 | hash -i "x" -a md5 | Click 选项错误 |
MUTUALLY EXCLUSIVE PARAMETER CASES
-e与-f:不能同时使用。
EDGE CASES
| 场景 | 命令 | 预期 |
|---|---|---|
| 空字符串 | hash -i "" | 正常(空摘要) |
| Unicode | hash -i "中文" | 正常 UTF-8 |
| 大文件 | hash -i large.bin -f | 流式计算 |
OUTPUT STRUCTURE EXPECTATION
| |
三、HMAC
3.1 hmac 命令
PURPOSE
计算 HMAC 消息认证码。支持 sha224、sha256、sha384、sha512、sha3_224、sha3_256、sha3_384、sha3_512、sm3。
BASIC USAGE
| |


VALID PARAMETER COMBINATIONS
| 组合 | 示例 |
|---|---|
| SHA256(默认) | easy_encryption_tool hmac -i "hello" |
| SHA384 | easy_encryption_tool hmac -i "hello" -a sha384 |
| SM3 | easy_encryption_tool hmac -i "hello" -a sm3 -k "01234567890123456789012345678901" |
| 随机 key | easy_encryption_tool hmac -i "hello" -r |
| Base64 输入 | easy_encryption_tool hmac -i "<b64>" -e |
| 文件输入 | easy_encryption_tool hmac -i /path/to/file -f |
| stdin 间接 | echo "data" | xargs -I {} easy_encryption_tool hmac -i {} -k "01234567890123456789012345678901" |
ADVANCED USAGE SCENARIOS
| |
INVALID INPUT EXAMPLES
| 命令 | 原因 | 预期错误 |
|---|---|---|
| SM3 key 长度不符 | hmac -a sm3 -k "short" -i "x" | SM3 HMAC key length must be X-Y bytes |
-e 与 -f 同时 | hmac -i x -e -f | 互斥错误 |
MUTUALLY EXCLUSIVE PARAMETER CASES
-e与-f:互斥。-r与-k:-r时 key 由工具生成,-k被忽略。
EDGE CASES
| 场景 | 命令 | 预期 |
|---|---|---|
| 空消息 | hmac -i "" -k "01234567890123456789012345678901" | 正常(空消息的 HMAC) |
| Unicode | hmac -i "中文" -k "01234567890123456789012345678901" | 正常 UTF-8 |
OUTPUT STRUCTURE EXPECTATION
| |
四、非对称加密
4.1 RSA 命令组
rsa generate
PURPOSE:生成 RSA 密钥对。
BASIC USAGE:
| |

VALID COMBINATIONS:
| 组合 | 示例 |
|---|---|
| 2048 位(默认) | easy_encryption_tool rsa generate -f demo -p 1234567890 |
| 3072/4096 位 | easy_encryption_tool rsa generate -s 3072 -f demo -p 1234567890 |
| 带密码 | easy_encryption_tool rsa generate -f demo -p 1234567890 |
| 随机密码 | easy_encryption_tool rsa generate -f demo -r |
| DER 编码 | easy_encryption_tool rsa generate -f demo -E der -p 1234567890 |
INVALID:-p 与 -r 同时使用(逻辑冲突,应只用其一)。
OUTPUT:result.public_file, result.private_file,可选 result.password。
rsa encrypt
PURPOSE:使用公钥加密。
BASIC USAGE:
| |
VALID COMBINATIONS:
| 组合 | 示例 |
|---|---|
| OAEP+SHA256(默认) | easy_encryption_tool rsa encrypt -f pub.pem -i "hello" |
| OAEP+SHA384 | easy_encryption_tool rsa encrypt -f pub.pem -i "hello" -m oaep -a sha384 |
| PKCS#1 v1.5 | easy_encryption_tool rsa encrypt -f pub.pem -i "hello" -m pkcs1v15 |
| Base64 输入 | easy_encryption_tool rsa encrypt -f pub.pem -i "<b64>" -e |
INVALID:
| 命令 | 原因 | 预期错误 |
|---|---|---|
| 明文超长 | 2048 RSA+OAEP+SHA256 明文 >190 字节 | plain size: X exceeds max allowed: 190 bytes |
| 非法 base64 | -e 且输入非法 | invalid b64 encoded data |
rsa decrypt
PURPOSE:使用私钥解密。
BASIC USAGE:
| |
VALID COMBINATIONS:与 encrypt 的 mode/hash 必须一致;私钥有密码时加 -p。
INVALID:密文/模式/哈希不匹配 → decrypt failed (invalid ciphertext or key/mode mismatch)。
rsa sign
PURPOSE:使用私钥签名。
BASIC USAGE:
| |
VALID COMBINATIONS:
| 组合 | 示例 |
|---|---|
| PSS+SHA256(默认) | easy_encryption_tool rsa sign -f pri.pem -i "hello" |
| PKCS#1 v1.5 | easy_encryption_tool rsa sign -f pri.pem -i "hello" -m pkcs1v15 -a sha256 |
| 摘要输入 | easy_encryption_tool rsa sign -f pri.pem -i "<32_byte_sha256_b64>" -e -d -a sha256 |
INVALID:-d 时输入长度必须等于 -a 对应摘要长度,否则 input-is-digest mode requires X bytes。
rsa verify
PURPOSE:使用公钥验签。
BASIC USAGE:
| |
INVALID:签名为空 → signature cannot be empty;验签失败 → InvalidSignature!。
五、ECC 命令组
5.1 ecc generate
PURPOSE:生成 ECC 密钥对。支持 secp256r1、secp384r1、secp521r1、secp256k1、ed25519、x25519。
BASIC USAGE:
| |
VALID COMBINATIONS:
| 曲线 | 用途 | 示例 |
|---|---|---|
| secp256r1/384r1/521r1 | ECDSA + ECDH | ecc generate -c secp256r1 -f demo |
| secp256k1 | ECDSA + ECDH | ecc generate -c secp256k1 -f demo |
| ed25519 | 仅签名 | ecc generate -c ed25519 -f demo |
| x25519 | 仅 ECDH | ecc generate -c x25519 -f demo |
| 带密码 | ecc generate -c secp256r1 -f demo -p pass | |
| 随机密码 | ecc generate -c secp256r1 -f demo -r |
5.2 ecc ecdh
PURPOSE:ECDH 密钥协商,派生共享密钥。不支持 Ed25519。
BASIC USAGE:
| |
VALID COMBINATIONS:
| 组合 | 示例 |
|---|---|
| 基本 | ecc ecdh -k alice_pri.pem -b bob_pub.pem |
| 可选校验己方公钥 | ecc ecdh -k alice_pri.pem -a alice_pub.pem -b bob_pub.pem |
| 自定义 HKDF 参数 | ecc ecdh -k a.pem -b b.pem -l 32 -H sha256 -s "salt" -c "context" |
| 私钥密码 | ecc ecdh -k a.pem -b b.pem -p password |
INVALID:
| 命令 | 原因 | 预期错误 |
|---|---|---|
| Ed25519 私钥 | Ed25519 仅签名 | ed25519 keys are for signing/verification only |
| X25519 与 secp 混用 | 曲线类型不匹配 | Key type mismatch |
| 同一密钥对 | 己方私钥与对方公钥同对 | Same key pair detected |
5.3 ecc sign
PURPOSE:ECDSA 或 Ed25519 签名。
BASIC USAGE:
| |
VALID COMBINATIONS:
| 曲线类型 | 示例 |
|---|---|
| secp* + SHA256 | ecc sign -f pri.pem -i "hello" -a sha256 |
| Ed25519(忽略 -a) | ecc sign -f ed25519_pri.pem -i "hello" |
| 摘要输入 | ecc sign -f pri.pem -i "<digest_b64>" -e -d -a sha256 |
INVALID:Ed25519 使用 -d → Ed25519 does not support -d/--input-is-digest;X25519 签名 → x25519 keys are for key exchange only。
5.4 ecc verify
PURPOSE:验证 ECDSA 或 Ed25519 签名。
BASIC USAGE:
| |
INVALID:X25519 公钥验签 → x25519 keys are for key exchange only;Ed25519 使用 -d → 不支持。
六、SM2 命令组
6.1 sm2 generate
PURPOSE:生成 SM2 密钥对。私钥必须设置 1–32 字节密码。
BASIC USAGE:
| |
VALID COMBINATIONS:
| 组合 | 示例 |
|---|---|
| 固定密码 | sm2 generate -f demo -p 12345678 |
| 随机密码 | sm2 generate -f demo -r |
INVALID:无密码或密码超 32 字节 → SM2 private key password must be 1-32 bytes。
6.2 sm2 encrypt
PURPOSE:SM2 公钥加密。
BASIC USAGE:
| |
VALID COMBINATIONS:
| 密文格式 | 示例 |
|---|---|
| C1C3C2_ASN1(默认) | sm2 encrypt -f pub.pem -i "hello" |
| C1C3C2/C1C2C3_ASN1/C1C2C3 | sm2 encrypt -f pub.pem -i "hello" -m C1C3C2 |
| hex 输出 | sm2 encrypt -f pub.pem -i "hello" -o hex |
6.3 sm2 decrypt
PURPOSE:SM2 私钥解密。必须提供 -p 密码。
BASIC USAGE:
| |
VALID COMBINATIONS:base64(默认)或 -x hex 输入;-m 需与加密一致。
6.4 sm2 sign
PURPOSE:SM2 签名。支持原始数据或 SM3 摘要。
BASIC USAGE:
| |
VALID COMBINATIONS:
| 组合 | 示例 |
|---|---|
| 原始数据 | sm2 sign -f pri.pem -i "hello" -p pass |
| SM3 摘要 | sm2 sign -f pri.pem -i "<32_byte_b64>" -e -d -p pass |
| RS 格式 | sm2 sign -f pri.pem -i "hello" -p pass -m RS |
| 自定义 signer-id | sm2 sign -f pri.pem -i "hello" -p pass --signer-id "custom" |
INVALID:-d 时输入非 32 字节 → input-is-digest mode requires SM3 digest (32 bytes)。
6.5 sm2 verify
PURPOSE:SM2 验签。
BASIC USAGE:
| |
VALID COMBINATIONS:--sig-hex 表示签名为 hex;-d 表示输入为 SM3 摘要。
七、随机数生成
7.1 random-str 命令
PURPOSE
使用 CSPRNG 生成指定长度的随机字符串(字母、数字、特殊字符)。
BASIC USAGE
| |
VALID PARAMETER COMBINATIONS
| 组合 | 示例 |
|---|---|
| 默认 32 字符 | easy_encryption_tool random-str |
| 指定长度 | easy_encryption_tool random-str -l 16 |
| 输出到文件 | easy_encryption_tool random-str -l 64 -o out.txt |
| 禁止覆盖 | easy_encryption_tool random-str -l 32 -o out.txt --no-force |
| JSON/Raw | easy_encryption_tool random-str -l 16 --json / --raw |
ADVANCED USAGE SCENARIOS
| |
INVALID INPUT EXAMPLES
| 命令 | 原因 | 预期错误 |
|---|---|---|
random-str -l 0 | 长度至少 1 | Click IntRange 错误 |
random-str -l -1 | 负数 | Click 错误 |
| 输出文件不可写 | random-str -o /nonexistent/path/file | try write to ... failed |
已存在文件 + --no-force | random-str -o existing.txt --no-force | 写入失败或跳过 |
MUTUALLY EXCLUSIVE PARAMETER CASES
- 无互斥参数。
-o与默认 stdout 输出二选一(有-o时写文件,否则输出到 stdout)。
EDGE CASES
| 场景 | 命令 | 预期 |
|---|---|---|
| 最小长度 | random-str -l 1 | 输出 1 个字符 |
| 超长输出 | random-str -l 1000000 | 分块生成,可能较慢 |
OUTPUT STRUCTURE EXPECTATION
| |
八、证书解析
8.1 cert-parse 命令
PURPOSE
解析 X.509 证书(PEM/DER)或国密 SM2 证书(PEM),并可选验证签名。注意:本命令输出为纯文本,不遵循 CipherHUB JSON schema,且不支持 --json/--raw。
BASIC USAGE
| |
VALID PARAMETER COMBINATIONS
| 组合 | 示例 |
|---|---|
| PEM(默认) | easy_encryption_tool cert-parse -f cert.pem |
| DER | easy_encryption_tool cert-parse -f cert.der -e der |
| 国密 SM2 | easy_encryption_tool cert-parse -f gm_cert.pem -g |
| 详细输出 | easy_encryption_tool cert-parse -f cert.pem -v |
INVALID INPUT EXAMPLES
| 命令 | 原因 | 预期错误 |
|---|---|---|
| 国密证书用 DER | cert-parse -f x.pem -g -e der | GM cert parse supports PEM only |
| 证书文件 >10KB | 大文件 | cert file ... size ... Bytes, too large (max 10KB) |
| 无效证书格式 | 损坏或非证书文件 | loading cert file ... failed |
九、主入口命令
9.1 install-completion
PURPOSE:安装 Shell 自动补全(bash/zsh/fish)。
BASIC USAGE:
| |
VALID:-s bash|zsh|fish,-p /path/to/script 输出到文件。
9.2 show-version(version)
PURPOSE:显示工具版本。
BASIC USAGE:
| |
十、CipherHUB 默认参数速查
| 参数 | 默认值 |
|---|---|
| AES key | 01234567890123456789012345678901 (32 字节) |
| AES/SM4 IV | 0123456789012345 (16 字节) |
| GCM nonce | 012345678901234567890123 (12 字节) |
| AAD | 密码学人 CipherHUB 默认 AAD 数据 |
| HMAC key | 01234567890123456789012345678901 (32 字节) |
| SM2 signer ID | 1234567812345678 |
| ECC salt | 密码学人【CipherHUB】 |
| ECC hash | sha512 |
| ECC derived key length | 32 |
十一、主结果键(–raw 模式)
| 命令 | 主结果键 |
|---|---|
| hash | digest |
| hmac | hmac |
| aes/sm4/zuc encrypt | cipher |
| aes/sm4/zuc decrypt | plain |
| random-str | value 或 output_file |
| rsa generate | public_file |
| rsa encrypt | cipher |
| rsa decrypt | plain |
| rsa sign | signature |
| rsa verify | valid |
| ecc generate | public_file |
| ecc ecdh | key |
| ecc sign | signature |
| ecc verify | valid |
| sm2 generate | public_file |
| sm2 encrypt | cipher |
| sm2 decrypt | plain |
| sm2 sign | signature |
| sm2 verify | valid |