Gmssl 基本使用

安装

git clone git@github.com:guanzhi/GmSSL.git
mkdir build
cd build
cmake ..
make
make test
sudo make install
sudo ldconfig

SM3

echo -n "abc" | gmssl sm3

usage: sm3 [-hex|-bin] [-pubkey pem [-id str]] [-in file] [-out file]

输出结果:

66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0

SM4

加密

gmssl sm4 -cbc_sm3_hmac -decrypt \
                        -key 112233445566778811223344556677881122334455667788112233445566778811223344556677881122334455667788 \
                        -iv 11223344556677881122334455667788 -in ciphertext.bin

usage: sm4 (-cbc|-ctr|-gcm|-cbc_sm3_hmac|-ctr_sm3_hmac) {-encrypt|-decrypt} -key hex -iv hex [-in file] [-out file]

解密

gmssl sm4 -cbc_sm3_hmac -decrypt \
                        -key 112233445566778811223344556677881122334455667788112233445566778811223344556677881122334455667788 \
                        -iv 11223344556677881122334455667788 -in ciphertext.bin

usage: sm4 (-cbc|-ctr|-gcm|-cbc_sm3_hmac|-ctr_sm3_hmac) {-encrypt|-decrypt} -key hex -iv hex [-in file] [-out file]

输出结果:

hello

SM2

密钥生成

gmssl sm2keygen -pass 123 -out sm2.key -pubout pub.key

usage: sm2keygen Options
    -pass pass                  Password to encrypt the private key
    -out pem                    Output password-encrypted PKCS #8 private key in PEM format
    -pubout pem                 Output public key in PEM format

输出私钥:sm2.key;公钥:pub.key

签名

gmssl sm2sign -key sm2.key -pass 123 -in test.txt -out sm2.sig

usage: sm2sign -key pem -pass str [-id str] [-in file] [-out file]

输出签名:sm2.sig

验签

gmssl sm2verify -pubkey pub.key -in test.txt -sig sm2.sig

usage: sm2verify (-pubkey pem | -cert pem) [-id str] [-in file] -sig file

输出:

verify : sucess

私钥签名,公钥验签

加密

echo "this world sucks, but you gonna like it!" >> world.txt

sm2encrypt -pubkey pub.key -in world.txt -out world.enc

usage: sm2encrypt (-pubkey pem | -cert pem) [-in file] [-out file]

输出:加密文件 world.enc

解密

gmssl sm2decrypt -key sm2.key -pass 123 -in world.enc -out world.dec

usage: sm2decrypt -key pem -pass str [-in file] [-out file]

输出:解密文件 world.dec

内容为

this world sucks, but you gonna like it!

公钥加密,私钥解密

产生随机数

gmssl rand -hex -outlen 10 -out randnum

usage: rand [-hex] [-rdrand] -outlen num [-out file]

输出文件:randnum

打开文件,显示

49688B89B9A0900E6D21
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值