本机需要安装openssl
生成私钥:
$ openssl ecparam -genkey -name SM2 -out SM2PrivateKey.pem
生成结果:
$ cat SM2PrivateKey.pem
-----BEGIN EC PARAMETERS-----
BggqgRzPVQGCLQ==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIIbHqfHf2cWCi9Qi76elQTdZGDeOA4z5029y1Rsq9sv8oAoGCCqBHM9V
AYItoUQDQgAEiLCv2e9tYqfevPl6kae15+w6bZU6iFCTpSFu4MLbrHlWIqVw91Vk
Z+uMH3jfFAZ4Ch18CtwahQmy3+5B62DiGg==
-----END EC PRIVATE KEY-----
私钥转换为pkcs8
openssl pkcs8 -topk8 -inform PEM -in sm2PriKey.pem -outform pem -nocrypt -out sm2PriKeyPkcs8.pem
生成公钥:
openssl ec -in SM2PrivateKey.pem -pubout -out SM2PublicKey.pem
生成结果:
$ cat SM2PrivateKey.pem
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAEiLCv2e9tYqfevPl6kae15+w6bZU6
iFCTpSFu4MLbrHlWIqVw91VkZ+uMH3jfFAZ4Ch18CtwahQmy3+5B62DiGg==
-----END PUBLIC KEY-----
网友评论