-1

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

Vikdor
  • 23,934
  • 10
  • 61
  • 84
randy
  • 1,685
  • 3
  • 34
  • 74
  • Why are you storing an encrypted password in your database? If it's a user's password it should be salted and hashed. – Andrew Cooper Nov 06 '12 at 02:13
  • I appreciate your opinion but that was not the question or was i asking for your opinion on how to save passwords. I have a legacy problem i am trying to solve – randy Nov 06 '12 at 02:38

1 Answers1

3

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.

Laurence Dougal Myers
  • 1,004
  • 1
  • 8
  • 17