2

I am a PHP developer(not an android developer). I outsourced the development of an Android app, and for communication between the app and my PHP server, I intend to have asymmetrical encryption(public-private key encryption).

At PHP level, I know openssl_public_encrypt and openssl_private_decrypt. I told the android developer to use OpenSSL public encryption and RSA encryption to use in-app, but it is not working.

I tried searching, but couldn't find any fruitful results.

Can anyone help me with this, so that I can tell my developer to use a particular method or something?

Purvik Dhorajiya
  • 4,662
  • 3
  • 34
  • 43
kadamb
  • 1,532
  • 3
  • 29
  • 55
  • OpenSSL is an implementation of SSL. You don't need to use the exact same library on each end. Just make sure you're using the same algorithms. Without seeing anything specific it's hard to guess what might be wrong. – Halcyon Jun 08 '17 at 14:55
  • Correct me if I am wrong, that RSA is used in openssl_public_encrypt, and I can simply encrypt using the public key and RSA algorithm app side? – kadamb Jun 08 '17 at 14:59

1 Answers1

1

I found out the answer. openssl_public_encrypt uses RSA algorithm and same can be used in Android in following way:

Cipher cipher = Cipher.getInstance(RSA);
cipher.init(Cipher.ENCRYPT_MODE, publicKey);

What I was doing wrong was using default encryption mode on both sides, PHP as well as Android, which was wrong as they differed.

For more details read : https://stackoverflow.com/a/17820910/3333052

kadamb
  • 1,532
  • 3
  • 29
  • 55