Hi,
Could you help me with my issue? I try to build CMS enveloped data with my certificate, but exception happens.
- OS
MacOS Mojave v10.14.6
- java version
1.8
- BC version
either 1.60 or 1.62
- My code
private String createCmsData(X509Certificate certificate, byte[] data) throws Exception {
Security.addProvider(new BouncyCastleProvider());
CMSEnvelopedDataGenerator envelopedGen = new CMSEnvelopedDataGenerator();
envelopedGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(certificate).setProvider("BC"));
CMSEnvelopedData ed = envelopedGen.generate(
new CMSProcessableByteArray(data),
new JceCMSContentEncryptorBuilder(NISTObjectIdentifiers.id_aes256_CBC).setProvider("BC").build());
// encode and return
...
}
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
37:1f:99:d0:37:cd:c1:9a:b2:96:82:d1:fd:85:46:03:14:50:76:3c
Signature Algorithm: sm2sign-with-sm3
Issuer: CN = my.ca.local
Validity
Not Before: Sep 2 02:14:11 2019 GMT
Not After : Sep 3 06:39:44 2019 GMT
Subject: CN = ds1, OU = Sign, O = PKU, L = BJ, ST = BJ, C = CN
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:37:2e:49:4a:92:c1:01:87:e5:09:01:93:05:35:
88:ed:2a:af:81:17:41:18:2c:0c:0c:33:11:54:9d:
8b:3c:d4:de:16:03:f8:df:fa:08:84:8a:54:1f:49:
50:a5:09:d5:e5:0c:d1:83:93:f8:44:fd:e8:70:61:
91:28:e5:65:0b
ASN1 OID: sm2p256v1
NIST CURVE: SM2
X509v3 extensions:
X509v3 Basic Constraints: critical
CA:FALSE
X509v3 Authority Key Identifier:
keyid:AB:46:5A:A6:73:C2:CC:C8:7E:00:76:B7:55:3F:1B:76:1E:7F:E5:FF
X509v3 Subject Key Identifier:
7E:7E:E5:C1:E2:40:F0:B6:FC:FD:2A:56:25:33:D7:B4:35:C6:3E:73
X509v3 Key Usage: critical
Digital Signature, Non Repudiation, Key Encipherment, Data Encipherment
Signature Algorithm: sm2sign-with-sm3
30:45:02:21:00:f7:86:6b:eb:b1:00:4a:d5:98:99:67:c4:f8:
8b:07:4d:11:ba:af:21:04:7b:53:90:f0:7b:f0:e4:5c:80:d7:
4b:02:20:6e:8d:7a:4d:6b:6c:45:c5:7e:02:d2:b2:01:3b:5e:
2c:50:a3:66:7d:51:d9:84:bc:7a:93:c0:68:28:a7:ce:30
exception wrapping content key: cannot create cipher: No such algorithm: 1.2.840.10045.2.1
org.bouncycastle.cms.CMSException: exception wrapping content key: cannot create cipher: No such algorithm: 1.2.840.10045.2.1
at org.bouncycastle.cms.KeyTransRecipientInfoGenerator.generate(Unknown Source)
at org.bouncycastle.cms.CMSEnvelopedDataGenerator.doGenerate(Unknown Source)
at org.bouncycastle.cms.CMSEnvelopedDataGenerator.generate(Unknown Source)
...
Caused by: org.bouncycastle.operator.OperatorCreationException: cannot create cipher: No such algorithm: 1.2.840.10045.2.1
at org.bouncycastle.operator.jcajce.OperatorHelper.createAsymmetricWrapper(Unknown Source)
at org.bouncycastle.operator.jcajce.JceAsymmetricKeyWrapper.generateWrappedKey(Unknown Source)
... 10 more
Caused by: java.security.NoSuchAlgorithmException: No such algorithm: 1.2.840.10045.2.1
at javax.crypto.Cipher.getInstance(Cipher.java:687)
at javax.crypto.Cipher.getInstance(Cipher.java:595)
at org.bouncycastle.jcajce.util.NamedJcaJceHelper.createCipher(Unknown Source)
... 12 more
Hi,
Could you help me with my issue? I try to build CMS enveloped data with my certificate, but exception happens.
MacOS Mojave v10.14.6
1.8
either 1.60 or 1.62
Certificate: Data: Version: 3 (0x2) Serial Number: 37:1f:99:d0:37:cd:c1:9a:b2:96:82:d1:fd:85:46:03:14:50:76:3c Signature Algorithm: sm2sign-with-sm3 Issuer: CN = my.ca.local Validity Not Before: Sep 2 02:14:11 2019 GMT Not After : Sep 3 06:39:44 2019 GMT Subject: CN = ds1, OU = Sign, O = PKU, L = BJ, ST = BJ, C = CN Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (256 bit) pub: 04:37:2e:49:4a:92:c1:01:87:e5:09:01:93:05:35: 88:ed:2a:af:81:17:41:18:2c:0c:0c:33:11:54:9d: 8b:3c:d4:de:16:03:f8:df:fa:08:84:8a:54:1f:49: 50:a5:09:d5:e5:0c:d1:83:93:f8:44:fd:e8:70:61: 91:28:e5:65:0b ASN1 OID: sm2p256v1 NIST CURVE: SM2 X509v3 extensions: X509v3 Basic Constraints: critical CA:FALSE X509v3 Authority Key Identifier: keyid:AB:46:5A:A6:73:C2:CC:C8:7E:00:76:B7:55:3F:1B:76:1E:7F:E5:FF X509v3 Subject Key Identifier: 7E:7E:E5:C1:E2:40:F0:B6:FC:FD:2A:56:25:33:D7:B4:35:C6:3E:73 X509v3 Key Usage: critical Digital Signature, Non Repudiation, Key Encipherment, Data Encipherment Signature Algorithm: sm2sign-with-sm3 30:45:02:21:00:f7:86:6b:eb:b1:00:4a:d5:98:99:67:c4:f8: 8b:07:4d:11:ba:af:21:04:7b:53:90:f0:7b:f0:e4:5c:80:d7: 4b:02:20:6e:8d:7a:4d:6b:6c:45:c5:7e:02:d2:b2:01:3b:5e: 2c:50:a3:66:7d:51:d9:84:bc:7a:93:c0:68:28:a7:ce:30