Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any Equivalent for mcrypt (in PHP) to use in Java?

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?

like image 545
Kris Avatar asked Oct 19 '11 13:10

Kris


1 Answers

Encryption algorithms are programming language independent.

As long as the:

  • Cipher (eg: AES, DES, Blowfish, etc.),
  • Mode of operation (eg: CBC, CTR, OFB, etc.) ,
  • Key,
  • IV and
  • Padding (mcrypt uses zero-padding)

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.

like image 64
NullUserException Avatar answered Oct 03 '22 22:10

NullUserException