anon.crypto
Class MD5Crypt

java.lang.Object
  extended by anon.crypto.MD5Crypt
All Implemented Interfaces:
ICrypt

public class MD5Crypt
extends java.lang.Object
implements ICrypt

Class containing static methods for encrypting passwords in FreeBSD md5 style.

Version:
1.0
Author:
Nick Johnson

Field Summary
private static java.lang.String itoa64
           
private static java.lang.String magic
           
 
Constructor Summary
MD5Crypt()
           
 
Method Summary
 java.lang.String crypt(java.lang.String password)
          Encrypts a password using FreeBSD-style md5-based encryption
 java.lang.String crypt(java.lang.String password, java.lang.String salt)
          Encrypts a password using FreeBSD-style md5-based encryption
private static java.lang.String cryptTo64(int value, int length)
           
static java.lang.String simpleHash(java.lang.String inputString)
          Takes an arbitrary String as input, and returns its MD5 hash value Note: NOT cryptographically secure, do not use this method to store passwords etc!!!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

magic

private static final java.lang.String magic
See Also:
Constant Field Values

itoa64

private static final java.lang.String itoa64
See Also:
Constant Field Values
Constructor Detail

MD5Crypt

public MD5Crypt()
Method Detail

cryptTo64

private static java.lang.String cryptTo64(int value,
                                          int length)

simpleHash

public static java.lang.String simpleHash(java.lang.String inputString)
Takes an arbitrary String as input, and returns its MD5 hash value Note: NOT cryptographically secure, do not use this method to store passwords etc!!!

Parameters:
inputString - String: any String
Returns:
String: the Base64-encoded md5 hash, or empty string on error

crypt

public final java.lang.String crypt(java.lang.String password)
                             throws java.security.NoSuchAlgorithmException
Encrypts a password using FreeBSD-style md5-based encryption

Specified by:
crypt in interface ICrypt
Parameters:
password - The cleartext password to be encrypted
Returns:
The encrypted password, or an empty string on error
Throws:
java.security.NoSuchAlgorithmException - if java.security does not support MD5

crypt

public final java.lang.String crypt(java.lang.String password,
                                    java.lang.String salt)
                             throws java.security.NoSuchAlgorithmException
Encrypts a password using FreeBSD-style md5-based encryption

Specified by:
crypt in interface ICrypt
Parameters:
password - The cleartext password to be encrypted
salt - The salt used to add some entropy to the encryption
Returns:
The encrypted password, or an empty string on error
Throws:
java.security.NoSuchAlgorithmException - if java.security does not support MD5