I've got some decryption problems in my Android project.
I'm getting a string signed with a private key and I have to verify(decrypt) it with a public key. I'd like to get exactly the same result as if I were using a PHP function - openssl_public_decrypt ( http://php.net/manual/pl/function.openssl-public-decrypt.php )
I have to do this in my Java project, so I can use Java libs (e.g BouncyCastle, or something else, any recommendations? )
Any ideas how to solve this?
Ok, here's my code. I'm getting the public key like this
PEMReader reader = new PEMReader(new InputStreamReader(ctx
.getAssets().open("pubkey.pem")));
Object obj;
while ((obj = reader.readObject()) != null) {
if (obj instanceof RSAPublicKey) {
pubKey = (RSAPublicKey) obj;
return pubKey;
}
}
And I always get the public key without any problems.
Cipher c = Cipher.getInstance("RSA/NONE/NoPadding", "SC");
c.init(Cipher.DECRYPT_MODE, pubKey);
byte[] result = c.doFinal(data_to_decrypt.getBytes());
And as a result(after converting bytes to string) I get 022c06571c6a263b389fcd93159cb311abb880bddf51b7c916dd1ae...
where php functions returns
sd8dsa348acvcx87|00454|OK|15000|CDE
and this is a correct output.