Raging Goblin

11 August 2012

Java alternative to PHP crypt function

Filed under: Java — raginggoblin @ 13:27
Tags: ,

For my Infolog program I needed a Java alternative to the PHP crypt function. After a little research I found a couple of Java implementations on an ftp site created by Jonathan Abbey and James Ratcliff. I wrote a small wrapper around these crypt functions to emulate the PHP functionality. Only the algorithms MD5, SHA256 and SHA512 are supported, but for me this will do. Feel free to extend its functionality.

Usage: java -jar Crypt.jar [String to encrypt] [salt]
Eg: java -jar Crypt.jar rasmuslerdorf $6$rounds=5000$usesomesillystringforsalt$
Will generate the output: $6$rounds=5000$usesomesillystri$D4IrlXatmP7rx3P3InaxBeoomnAihCKRVQP22JZ6EY47Wc6BkroIuUUBOov1i.S5KPgErtP/EN5mcO.ChWQW21
Or you can call the static method public static String crypt(String toCrypt, String salt) on Crypt.java after importing the sources or the binary jar into your project.

Binaries: https://docs.google.com/open?id=0B2BnX0ubpIbcaWg1dDY2Rmd5c2M
Sources: https://docs.google.com/open?id=0B2BnX0ubpIbcU3ZiOW9lTjlxb1U

4 Comments »

  1. oh my god !
    this saved my life
    thank you :)

    Comment by phendrax — 2 November 2012 @ 15:14 | Reply

  2. A minor bug in Sha512Crypt.java (on the ftp site): In the verifyPassword function:

    “return sha512CryptText.equals(Sha512_crypt(plaintextPass, sha512CryptText, 0));”

    does not make sense! Sha512_crypt returns entire encrypted string and it is being compare to just the key – will be false always.

    Comment by Fergus Incrisis — 8 January 2013 @ 23:08 | Reply

  3. Hey buddy, i have this error on crypt: raging.goblin.crypt.CryptException: Could not determine algorithm through provided salt: mysalt
    Can you help me?

    Comment by Samir Ortiz — 2 April 2014 @ 18:30 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Create a free website or blog at WordPress.com.

%d bloggers like this: