简体   繁体   English

Java和C ++密码学的互操作性

[英]Java and C++ Cryptography interoperability

I have a message coming from an external company which has been encrypted with our public key using Java. 我收到一则来自外部公司的消息,该消息已使用Java用我们的公共密钥加密。

Specifically the java code performing the encryption is - 具体来说,执行加密的Java代码是-

  //get instance of cipher using BouncyCastle cryptography provider 
  Cipher cipher = Cipher.getInstance( "RSA/ECB/PKCS1Padding", "BC"); 

  //initialize the cipher with the public key pulled from the X509 certificate 
  cipher.init(Cipher.ENCRYPT_MODE, publicKey); 

I need to be able to decrypt this message using our private key using C/C++ on Solaris. 我需要能够在Solaris上使用C / C ++使用我们的私钥来解密此消息。 I have tried using the Crypto++ library and can successfully encode decode messages just using Crypto++, but am unable to work out how to decode the message encrypted from the java side. 我已经尝试过使用Crypto ++库,并且仅使用Crypto ++就可以成功地编码解码消息,但是无法弄清楚如何解码从Java端加密的消息。

Specifically I tried using a RSAES_PKCS1v15_Decryptor but this does not seem to work. 具体来说,我尝试使用RSAES_PKCS1v15_Decryptor,但这似乎不起作用。

Does anyone have any suggestions as to how I can perform the decryption such as 是否有人对我如何执行解密有任何建议,例如

  1. The required Crypto++ code (ideal) 所需的Crypto ++代码(理想)
  2. Alternatives to RSA/ECB/PKCS1Padding to use from the Java side 从Java端使用RSA / ECB / PKCS1Padding的替代方法
  3. Alternative open source C libraries I could try 我可以尝试的替代开源C库
  4. Anything else... 还要别的吗...

I managed to get this working by changing the java code to use 我设法通过更改要使用的Java代码来使其工作

Cipher cipher = Cipher.getInstance( "RSA/NONE/PKCS1Padding", "BC");

This then matches up with RSAES_PKCS1v15_Decryptor on the Crypto++ side. 然后,它与Crypto ++端的RSAES_PKCS1v15_Decryptor相匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM