Search code examples
javaphpencryptionmcrypt

trying to decrypt via php a password that i encrypted with javav


so my java looks like

String epassword = Crypt.encryptStringToString((String) params.get("password"));

I then store that in a DB. I need to decrypt it with PHP.

Is there a way to do this?

Thanks


Solution

  • I assume you are using uk.org.ellery.twiki.Crypt, since that's the only thing that came up when I search on Google for "encryptStringToString java".

    In PHP, you will need to re-implement the class linked here:

    http://svn.foswiki.org/trunk/EncryptedPagesPlugin/uk/org/ellery/twiki/Crypt.java

    You're specifically interested in the "decryptString" method.

    If it helps, looks like it generates a random salt which is stored with the encrypted value in the first 8 bytes, and the algorithm to apply the actual encryption/decryption is "PBEWithMD5AndDES", as provided by the standard Java crypto libraries. However, there's some wrapper code to convert values into hex values and a Base64 string (and vice versa).

    Looks like someone has already ported PBEWithMD5AndDES to PHP, so you just need to re-write the Crypt.java file in PHP.