sm2格式数字信封
0、参考链接
密码行业标准化技术委员会
http://www.gmbz.org.cn/main/bzlb.html
SM2密码算法使用规范
http://www.gmbz.org.cn/main/viewfile/2018011001400692565.html
SM2密码算法应用分析
https://blog.youkuaiyun.com/arlaichin/article/details/23708155?utm_source=itdadao&utm_medium=referral
技术科普 | 国密算法在Ultrain区块链中的运用
https://blog.youkuaiyun.com/Tramp_1/article/details/111603396
1、sm2数字信封格式:
有效部分
公钥:04|X|Y,共65字节
私钥:整数,共32字节
SM2EnvelopedKey ::= SEQUENCE {
symalgid AlgorithmIdentifier, -- 对称算法ID
symalgkey SM2Cipher, -- 对称算法密钥(被签名证书公钥加密)
asympubkey BIT STRING, -- 加密证书公钥
asymprvkey BIT STRING -- 加密证书私钥(被对称算法加密)
}
typedef struct SM2Cipher_st {
ASN1_INTEGER *xCoordinate; // x分量(随机,非公钥)
ASN1_INTEGER *yCoordinate; // y分量(随机,非公钥)
ASN1_OCTET_STRING *hash; // 杂凑值
ASN1_OCTET_STRING *cipherText; // 密文
} SM2Cipher;
AlgorithmIdentifier ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
parameters ANY DEFINED BY algorithm OPTIONAL
}
区分普通的数字信封格式,见下图(openssl暂不支持sm2算法的私钥p7信封格式生成,但是支持sm2算法私钥的p7解密,生成p7可以在外部使用gmssl命令行生成)
typedef struct pkcs7_enveloped_st {
ASN1_INTEGER *version;
STACK_OF(PKCS7_RECIP_INFO) *recipientinfo