ikrs.httpd
Class MD5

java.lang.Object
  extended by ikrs.httpd.MD5

public class MD5
extends java.lang.Object

This a customized MD5 wrapper.


Field Summary
static java.lang.String IDENTIFIER_STRING
           
 
Method Summary
static java.lang.String ikrsMD5(java.lang.String salt, java.lang.String user, java.lang.String realm, char[] passData)
          This method encodes the MD5 hash of 'user + realm + passData' and builts the encrypted password line (to store in a .htpassword file).
static boolean isIKRSMD5(java.lang.String str)
          This method checks if the passed string is in the IKRS-MD5 format (such as hashes are stored in MY htaccess-files).
static void main(java.lang.String[] argv)
          This main-method can be used to run this program and create new .htpasswd entries.
static byte[] md5(byte[] data)
          This method uses the default MD5 message digest algorithm to encode the passed byte data.
static java.lang.String[] splitIKRSMD5(java.lang.String str)
          This method splits the passed password-encrypted text line into 4 segments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDENTIFIER_STRING

public static final java.lang.String IDENTIFIER_STRING
See Also:
Constant Field Values
Method Detail

isIKRSMD5

public static boolean isIKRSMD5(java.lang.String str)
                         throws java.lang.NullPointerException
This method checks if the passed string is in the IKRS-MD5 format (such as hashes are stored in MY htaccess-files). The passed string must not be null.

Throws:
java.lang.NullPointerException

splitIKRSMD5

public static java.lang.String[] splitIKRSMD5(java.lang.String str)
                                       throws java.lang.NumberFormatException
This method splits the passed password-encrypted text line into 4 segments. The line must have the format: ${ikrs.http.MD5}$ssssssss$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Where 's' is the salt (8 characters!) and 'x' is the MD5-encrypted user, password and realm data (32 hex chars). If the passed lines does not match the expected format a NumberFormatException will be thrown.

Throws:
java.lang.NumberFormatException

ikrsMD5

public static java.lang.String ikrsMD5(java.lang.String salt,
                                       java.lang.String user,
                                       java.lang.String realm,
                                       char[] passData)
                                throws java.security.NoSuchAlgorithmException,
                                       java.io.UnsupportedEncodingException
This method encodes the MD5 hash of 'user + realm + passData' and builts the encrypted password line (to store in a .htpassword file). The returned string can be splitted by the use of the splitIKRSMD5 method.

Parameters:
salt - The salt must be a 8-character string; I encourage you to use base64 chars only (for later compatibility with apache-MD5).
user - The username, must not be empty and should consist of alpha-numeric chars. No colons ':' are allowed.
realm - The realm name. This can be any non-empty string and should match _exactly_ (!) the realm name from your .htaccess file.
passData - The actual password as a char-array.
Throws:
java.security.NoSuchAlgorithmException
java.io.UnsupportedEncodingException
See Also:
MD5.splitIKRSMD5( String )

md5

public static byte[] md5(byte[] data)
                  throws java.security.NoSuchAlgorithmException
This method uses the default MD5 message digest algorithm to encode the passed byte data. The returned byte array contains exactly 16 bytes.

Parameters:
data - The data to encrypt.
Throws:
java.security.NoSuchAlgorithmException

main

public static void main(java.lang.String[] argv)
This main-method can be used to run this program and create new .htpasswd entries. Just type: java ikrs.http.MD5