使用Java和BouncyCastle,我可以解密许多S / MIME封装消息。
但是当密钥加密算法为1.2.840.113549.1.1.7
(id-RSAES-OAEP)时,解密失败(此问题末尾的堆栈跟踪)。
发生的行:
content = messageRecipientInfo.getContent(new JceKeyTransEnvelopedRecipient(pc).setProvider("BC"));
以前我用这行来解密:
content = messageRecipientInfo.getContent(givenCertRecipient);
一切都一样。
有什么猜测吗?
我现在尝试使用OAEP加密数据。因此,我在文件cms / test / NewEnvelopedDataTest.java中直接在BouncyCastle中找到了代码 即便这样也行不通! 同样的错误:
String BC = BouncyCastleProvider.PROVIDER_NAME;
KeyPair _reciKP = CMSTestUtil.makeKeyPair();
String _reciDN = "CN=Doug, OU=Sales, O=Bouncy Castle, C=AU";
KeyPair _signKP = CMSTestUtil.makeKeyPair();
String _signDN = "O=Bouncy Castle, C=AU";
X509Certificate _reciCertOaep = CMSTestUtil.makeOaepCertificate(_reciKP, _reciDN, _signKP, _signDN);
byte[] data = "WallaWallaWashington".getBytes();
CMSEnvelopedDataGenerator edGen = new CMSEnvelopedDataGenerator();
JcaAlgorithmParametersConverter paramsConverter = new JcaAlgorithmParametersConverter();
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(_reciCertOaep).setProvider(BC));
edGen.addRecipientInfoGenerator(new JceKeyTransRecipientInfoGenerator(ASN1OctetString.getInstance(ASN1OctetString.getInstance(_reciCertOaep.getExtensionValue(Extension.subjectKeyIdentifier.getId())).getOctets()).getOctets(), _reciCertOaep.getPublicKey()).setProvider(BC));
在最后一步中崩溃:"无法初始化算法参数:操作不受支持"
CMSEnvelopedData edd = edGen.generate(
new CMSProcessableByteArray(data),
new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC).setProvider(BC).build());
有什么问题?我看不到......
org.bouncycastle.cms.CMSException:异常解包密钥:不能 初始化算法参数:不支持的操作 org.bouncycastle.cms.jcajce.JceKeyTransRecipient.extractSecretKey(JceKeyTransRecipient.java:169) 在 org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient.getRecipientOperator(JceKeyTransEnvelopedRecipient.java:26) 在 org.bouncycastle.cms.KeyTransRecipientInformation.getRecipientOperator(KeyTransRecipientInformation.java:48) 在 org.bouncycastle.cms.RecipientInformation.getContentStream(RecipientInformation.java:169) 在 org.bouncycastle.cms.RecipientInformation.getContent(RecipientInformation.java:150) 在CryptoTools.decryptAndVerifyFile(CryptoTools.java:1030)at FormMain $ 2.actionPerformed(FormMain.java:403)at javax.swing.AbstractButton.fireActionPerformed(未知来源)at javax.swing.AbstractButton $ Handler.actionPerformed(Unknown Source)at javax.swing.DefaultButtonModel.fireActionPerformed(未知来源)at javax.swing.DefaultButtonModel.setPressed(未知来源)at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(未知 来自)java.awt.Component.processMouseEvent(未知来源)at javax.swing.JComponent.processMouseEvent(未知来源)at java.awt.Component.processEvent(未知来源)at java.awt.Container.processEvent(未知来源)at java.awt.Component.dispatchEventImpl(未知来源)at java.awt.Container.dispatchEventImpl(未知来源)at java.awt.Component.dispatchEvent(未知来源)at java.awt.LightweightDispatcher.retargetMouseEvent(未知来源)at java.awt.LightweightDispatcher.processMouseEvent(未知来源)at java.awt.LightweightDispatcher.dispatchEvent(未知来源)at java.awt.Container.dispatchEventImpl(未知来源)at java.awt.Window.dispatchEventImpl(未知来源)at java.awt.Component.dispatchEvent(未知来源)at java.awt.EventQueue.dispatchEventImpl(未知来源)at java.awt.EventQueue.access $ 500(未知来源)at java.awt.EventQueue $ 3.run(未知来源)at java.awt.EventQueue $ 3.run(未知来源)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(未知 来源)at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(未知 来自)java.awt.EventQueue $ 4.run(未知来源)at java.awt.EventQueue $ 4.run(未知来源)at java.security.AccessController.doPrivileged(Native Method)at java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(未知 来自)java.awt.EventQueue.dispatchEvent(未知来源)at java.awt.EventDispatchThread.pumpOneEventForFilters(未知来源) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 在java.awt.EventDispatchThread.pumpEventsForHierarchy(未知 来自java.awt.EventDispatchThread.pumpEvents(未知来源) at java.awt.EventDispatchThread.pumpEvents(Unknown Source)at java.awt.EventDispatchThread.run(未知来源)引起: org.bouncycastle.operator.OperatorCreationException:无法初始化 算法参数:不支持的操作 org.bouncycastle.operator.jcajce.OperatorHelper.createAlgorithmParameters(OperatorHelper.java:254) 在 org.bouncycastle.operator.jcajce.JceAsymmetricKeyUnwrapper.generateUnwrappedKey(JceAsymmetricKeyUnwrapper.java:100) 在 org.bouncycastle.cms.jcajce.JceKeyTransRecipient.extractSecretKey(JceKeyTransRecipient.java:158) ... 42更多引起:java.io.IOException:不支持操作 在 org.bouncycastle.jcajce.provider.asymmetric.rsa.AlgorithmParametersSpi $ OAEP.engineInit(AlgorithmParametersSpi.java:83) at java.security.AlgorithmParameters.init(Unknown Source)at org.bouncycastle.operator.jcajce.OperatorHelper.createAlgorithmParameters(OperatorHelper.java:250) ... 44更多