Raging Goblin

11 August 2012

Java alternative to PHP crypt function

Filed under: Java — Raging Goblin @ 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


Blog at WordPress.com.