mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-27 12:46:18 +08:00
pkcs7: follow GB/T 35275-2017 9.1 strictly
This commit is contained in:
parent
0445d16e97
commit
dc66ca673e
@ -33,17 +33,22 @@
|
|||||||
关于```EncryptSM / EncryptCFCA```的区别,请参考**CFCA互操作性指南**。
|
关于```EncryptSM / EncryptCFCA```的区别,请参考**CFCA互操作性指南**。
|
||||||
带PSK(Pre-shared key)后缀的方法,其对称加密密钥由调用者提供,而非随机生成。
|
带PSK(Pre-shared key)后缀的方法,其对称加密密钥由调用者提供,而非随机生成。
|
||||||
|
|
||||||
|
### 加密数据(Encrypted Data)
|
||||||
|
加密:对应本项目的```pkcs7.EncryptUsingPSK```和```pkcs7.EncryptSMUsingPSK```方法。
|
||||||
|
解密:对应本项目的```pkcs7.DecryptUsingPSK```方法(当然要先调用```pkcs7.Parse```)。
|
||||||
|
|
||||||
### 签名数据(Signed Data)
|
### 签名数据(Signed Data)
|
||||||
签名数据,使用证书对应的私钥进行签名,理论上支持多个签名者,但通常使用场景都是单签。和数字信封数据类似,也分国密和非国密。
|
签名数据,使用证书对应的私钥进行签名,理论上支持多个签名者,但通常使用场景都是单签。和数字信封数据类似,也分国密和非国密。
|
||||||
|
|
||||||
#### 创建签名数据
|
#### 创建签名数据
|
||||||
(是否国密是指OID也使用国密体系)
|
(是否国密是指OID也使用国密体系)
|
||||||
|
|
||||||
| 是否国密 | 方法 |
|
| 是否国密 | 方法 | 默认签名算法 |
|
||||||
| :--- | :--- |
|
| :--- | :--- | :--- |
|
||||||
| 否 | ```NewSignedData``` |
|
| 否 | ```NewSignedData``` | SHA1 |
|
||||||
| 是 | ```NewSMSignedData``` |
|
| 是 | ```NewSMSignedData``` | SM3 |
|
||||||
|
|
||||||
|
可选步骤:调用```SetDigestAlgorithm```设置想要的签名算法,通常国密不需要修改。
|
||||||
接着调用```AddSigner```或```AddSignerChain```方法,进行签名;可以通过```SignerInfoConfig.SkipCertificates```指定忽略证书项(最终签名数据中不包含证书项);
|
接着调用```AddSigner```或```AddSignerChain```方法,进行签名;可以通过```SignerInfoConfig.SkipCertificates```指定忽略证书项(最终签名数据中不包含证书项);
|
||||||
如果进行Detach签名,则调用```Detach```方法;
|
如果进行Detach签名,则调用```Detach```方法;
|
||||||
最后调用```Finish```方法,序列化输出结果。
|
最后调用```Finish```方法,序列化输出结果。
|
||||||
|
@ -112,6 +112,7 @@ func encrypt(cipher pkcs.Cipher, content []byte, recipients []*smx509.Certificat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if isSM {
|
if isSM {
|
||||||
|
envelope.Version = 1 // follow GB/T 35275-2017 9.1
|
||||||
envelope.EncryptedContentInfo.ContentType = SM2OIDData
|
envelope.EncryptedContentInfo.ContentType = SM2OIDData
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +142,9 @@ func encrypt(cipher pkcs.Cipher, content []byte, recipients []*smx509.Certificat
|
|||||||
},
|
},
|
||||||
EncryptedKey: encrypted,
|
EncryptedKey: encrypted,
|
||||||
}
|
}
|
||||||
|
if isSM {
|
||||||
|
info.Version = 1 // follow GB/T 35275-2017 9.1
|
||||||
|
}
|
||||||
recipientInfos[i] = info
|
recipientInfos[i] = info
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,6 +203,7 @@ func encryptUsingPSK(isSM bool, cipher pkcs.Cipher, content []byte, key []byte)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
if isSM {
|
if isSM {
|
||||||
|
ed.Version = 1 // follow GB/T 35275-2017 9.1
|
||||||
ed.EncryptedContentInfo.ContentType = SM2OIDData
|
ed.EncryptedContentInfo.ContentType = SM2OIDData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user