0

I am trying to decrypt data with rsa public key which is encrypted in java program with private key.

There is an answer which implement decryption in java program.

The problem is that I have to decrypt it in python program, but I found there is no interface in python packages like pyOpenSSL, Pycrypto, Cryptography.

Did I miss some information in these packages?
Or is there any other method to do it in python?

Community
  • 1
  • 1
triostones
  • 51
  • 7
  • 1
    In general encryption data with the private key is wrong, generally private key encryption is used for digital signatures. – zaph Jul 01 '16 at 03:27
  • @zaph Yes, in general, it should be encrypt with public key and decrypt with private key. but the data is from other remote server. I can not change their program. And how does java can decrypt with public key? – triostones Jul 01 '16 at 04:09
  • Look at digital signature methods. – zaph Jul 01 '16 at 04:12
  • But the java demo program offered by remote server is using [`Cipher.decrypt`](https://docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html#doFinal(byte[])), which is working ! – triostones Jul 01 '16 at 04:23
  • @triostones Earlier RSA standard (PKCS#1 v1) talks about signature generation as RSA encryption of a (padded) hash. In v2.1 they changed that fortunately. The fact is though that both signature generation use *modular exponentiation*, something that is also called raw or textbook RSA. So to do that in Python you need a library or function that is able to perform raw or textbook RSA. That said, the best thing to do is to tell the other guys they don't understand crypto and that they should restart their project. – Maarten Bodewes Jul 01 '16 at 13:18
  • Could OpenSSL with RSA_NO_PADDING work for you? – Maarten Bodewes Jul 01 '16 at 13:25
  • @MaartenBodewes Thanks for your comment. Your first comment is what I wanted. I found it at [here](https://wiki.openssl.org/index.php/Manual:RSA_private_encrypt(3)). And [M2Crypto](https://gitlab.com/m2crypto/m2crypto) do support this feature which do not support python3 sadly. – triostones Jul 04 '16 at 14:09

0 Answers0