gmssl sm2 加解密
时间: 2023-11-27 18:46:35 浏览: 89
iOS GMSSL国密sm2加解密
以下是使用gmssl进行sm2加解密的步骤:
1. 生成密钥对
```shell
# 生成私钥
openssl ecparam -genkey -name sm2p256v1 -out sm2.key
# 生成公钥
openssl ec -in sm2.key -pubout -out sm2.pub
```
2. 使用gmssl进行sm2加密
```shell
# 加密
echo "hello world" > plain.txt
gmssl sm2enc -in plain.txt -out cipher.txt sm2.pub
```
3. 使用gmssl进行sm2解密
```shell
# 解密
gmssl sm2dec -in cipher.txt -out plain2.txt sm2.key
```
4. 运行结果
```shell
$ cat plain.txt
hello world
$ cat cipher.txt
30819F300D06092A864886F70D010101050003818D0030818902818100B9C7E5B8B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5B7B7C5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