6

Can any one tell about any library that can be used in java, which gives the same result if operation was done in PHP using the mcrypt library.

i want to actually encrypt a string in Java using AES, and decrypt it in PHP. Will the Java Cipher yield a encryption decryptable by mcrypt in PHP?

edit:

Found some resin-3.1 library in Web. Can it be?

Kris
  • 8,680
  • 4
  • 39
  • 67
  • 2
    AES is a standard, assuming you set the cipher up the same way in Java and PHP, decryption will yield the original plaintext regardless of programming language. Mind you, encryption works on *bytes*, not strings. If you're processing text you'll also have to make sure you're converting it to / from a byte array using the same encoding. – millimoose Oct 19 '11 at 13:10
  • 1
    Thats Ok. I just wanted to know about any jar libraries that provide API's similar to mcrypt – Kris Oct 20 '11 at 06:14
  • 1
    Not sure about similar APIs. The standard one is JCE, which comes with the JDK and includes AES: http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html . There's also Legion of the Bouncy Castle which provides more algorithms and a "lightweight" alternative API: http://bouncycastle.org/ – millimoose Oct 20 '11 at 12:42

1 Answers1

11

Encryption algorithms are programming language independent.

As long as the:

are all the same, you'll be able to encrypt and decrypt data regardless of the programming language used (assuming the implementations are correct).

Just remember that Java's Cipher works on byte arrays, so if you are encrypting a string, you'll need to use String.getBytes() to get a byte array.

NullUserException
  • 83,810
  • 28
  • 209
  • 234