1、svn下载
用svn工具下载主干代码
https://github.com/guanzhi/GmSSL.git/trunk
2、编译
按照手册
./config no-saf no-sdf no-skf no-sof no-zuc
make
sudo make install
3、设置
ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
否则会报错:
gmssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
gmssl: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
4、unable to write 'random state'
查看/root目录是否存在,~/.rnd的所有者是root,所以执行命令加sudo可以解决
5、生成SM2私钥及证书请求
gmssl ecparam -genkey -name sm2p256v1 -out sm2key.pem
sm3做签名
gmssl req -new -sm3 -key sm2key.pem -out test.csr -subj "/CN=051@企业国密测试证书@Z1111111@1/OU=Organizational-1/OU=oca31/O=CFCA TEST CA/C=CN"
6、查看证书请求内容
gmssl req -in test.csr -noout -text -subject
7、查看私钥信息
gmssl ec -in sm2key.pem -text
将priv这一块提取出来
priv:
9d:b9:05:d2:27:78:cb:39:d2:f3:46:16:24:df:5d:
60:35:e5:c7:55:3c:1c:7e:69:fb:40:49:17:c7:bb:
dd:6b
去除分号和换行,获得私钥明文:32bit共64个16进制
9db905d22778cb39d2f3461624df5d6035e5c7553c1c7e69fb404917c7bbdd6b
8、访问cfca网站
https://cstest.cfca.com.cn
选:Web服务器证书下载
填入两码和P10请求文件内容
点击保存证书
9、(只是笔记)
根据业务需要将私钥转换成base64格式
public class Test {
public static void main(String[] args) {
byte[] aa = {(byte)0xd2,(byte)0x84,(byte)0xa1,(byte)0x10,(byte)0xa0,(byte)0x7b,(byte)0xe3,(byte)0x71,(byte)0xa0,(byte)0x95,(byte)0xcf,(byte)0x58,(byte)0x1f,(byte)0x47,(byte)0x0d,(byte)0xe4,(byte)0x2e,(byte)0xa7,(byte)0x6b,(byte)0x16,(byte)0x10,(byte)0x23,(byte)0x1b,(byte)0xf5,(byte)0xb9,(byte)0x09,(byte)0xdf,(byte)0x38,(byte)0x0b,(byte)0x61,(byte)0x9a,(byte)0xbf};
System.out.println(Base64.encodeBase64String(aa));
}