生成流程
- 下载openssl源码:
curl -o openssl-1.1.1d.tar.gz https://www.openssl.org/source/openssl-1.1.1d.tar.gz
- 解压源码包:
tar -xvf openssl-1.1.1d.tar.gz
- 进入解压出的openssl目录:
cd openssl-1.1.1d
- 配置生成makefile:
./config --prefix=/usr/local/openssl
- 编译、安装:
make install
- 生成SM2密钥对:
- 进入生成密钥文件的目录,执行以下命令生成私钥
/usr/local/openssl/bin/openssl ecparam -genkey -name SM2 -out SM2PrivateKey.pem
- 执行以下命令生成公钥
/usr/local/openssl/bin/openssl ec -in SM2PrivateKey.pem -pubout -out SM2PublicKey.pem
- 结果示例: 国密SM2私钥SM2PrivateKey.pem
-----BEGIN EC PARAMETERS-----
BggqgRzPVQGCLQ==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIOHSA5sO6QbqmGM1mrtplIDUth92o3yyPh7R6C7jhsS2oAoGCCqBHM9V
AYItoUQDQgAE6fyV2irf4j5DxR3BRidJ3v30TFavyz6skDPjA8TQgoMJF3iCFbqV
B4GxVcjkqucDPZ1khgq9l72krT7Lg0Yqag==
-----END EC PRIVATE KEY-----
国密SM2公钥SM2PublicKey.pem
代码语言:javascript复制-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE6fyV2irf4j5DxR3BRidJ3v30TFav
yz6skDPjA8TQgoMJF3iCFbqVB4GxVcjkqucDPZ1khgq9l72krT7Lg0Yqag==
-----END PUBLIC KEY-----
参考:https://segmentfault.com/a/1190000021758503