赞
踩
1. 生成SM2密钥对
gmssl ecparam -genkey -name sm2p256v1 -out sm2keypair.pem -text
2.查看SM2密钥对
gmssl ec -in sm2keypair.pem -text
3.生成自签名证书
gmssl req -x509 -key sm2keypair.pem -subj "/C=CN/ST=BJ/L=BJ/O=HD/OU=dev
/CN=hello/emailAddress=hello@world.com" -out sm2cert.pem
4.查看证书详情
gmssl x509 -in sm2cert.pem -text
5.证书加密明文数据
echo "12345678900987654321" > plain.dat
gmssl sm2utl -encrypt -inkey sm2cert.pem -certin -in plain.dat -out cipher.dat
6.私钥解密密文数据
gmssl sm2utl -decrypt -inkey sm2keypair.pem -in cipher.dat -out recov.dat
cat recov.dat
7.私钥签名消息
echo "12345678900987654321" > msg.dat
gmssl sm2utl -sign -inkey sm2keypair.pem -in msg.dat -out sign.dat -id "1234567812345678"
8.证书验证消息签名
gmssl sm2utl -verify -inkey sm2keypair.pem -in msg.dat -sigfile sign.dat -id "1234567812345678"
附录示例:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。