org.hsqldb.lib
Class MD5

java.lang.Object
  extended byorg.hsqldb.lib.MD5

public final class MD5
extends Object

Provides a static utility interface to an MD5 digest algorithm obtained through the java.security.MessageDigest spi.

Database end-users may wish to access the services of this class to provide, for instance, application user lookup tables with one-way password encryption. For example:

 -- DDL
 CREATE TABLE USERS(UID INTEGER IDENTITY, UNAME VARCHAR, UPASS VARCHAR, UNIQUE(UNAME))
 CREATE ALIAS MD5 FOR "org.hsqldb.lib.MD5.encodeString"

 -- DML & DQL
 INSERT INTO USERS(UNAME, UPASS) VALUES('joe', MD5('passwd'))
 UPDATE USERS SET UPASS = MD5('newpasswd') WHERE UNAME = 'joe' AND UPASS = MD5('oldpasswd')
 SELECT UID FROM USERS WHERE UNAME = 'joe' AND UPASS = MD5('logonpasswd')
 
NOTE:

Although it is possible that a particular JVM / application installation may encounter NoSuchAlgorithmException when attempting to get a jce MD5 message digest generator, the likelyhood is very small for almost all JDK/JRE 1.1 and later JVM implementations, as the Sun java.security package has come, by default, with a jce MD5 message digest generator since JDK 1.1 was released. The HSLQLDB project could have provided an MD5 implementation to guarantee presence, but this class is much more lightweight and still allows clients to install / use custom implementations through the java.security.MessageDigest spi, for instance if there is no service provided by default under the target JVM of choice or if a client has developed / provides, say, a faster MD5 message digest implementation. In short, this class is a convenience that allows HSQLDB SQL Function and Stored Procedure style access to any underlying MD5 message digest algorithm obtained via the java.security.MessageDigest spi

Since:
1.7.2
Version:
1.7.2
Author:
boucherb@users.sourceforge.net

Constructor Summary
MD5()
           
 
Method Summary
static byte[] digestBytes(byte[] data)
          Retrieves a byte sequence representing the MD5 digest of the specified byte sequence.
static byte[] digestString(String string, String encoding)
          Retrieves a byte sequence representing the MD5 digest of the specified character sequence, using the specified encoding to first convert the character sequence into a byte sequence.
static String encodeString(String string, String encoding)
          Retrieves a hexidecimal character sequence representing the MD5 digest of the specified character sequence, using the specified encoding to first convert the character sequence into a byte sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MD5

public MD5()
Method Detail

encodeString

public static final String encodeString(String string,
                                        String encoding)
                                 throws RuntimeException
Retrieves a hexidecimal character sequence representing the MD5 digest of the specified character sequence, using the specified encoding to first convert the character sequence into a byte sequence. If the specified encoding is null, then ISO-8859-1 is assumed

Parameters:
string - the string to encode.
encoding - the encoding used to convert the string into the byte sequence to submit for MD5 digest
Returns:
a hexidecimal character sequence representing the MD5 digest of the specified string
Throws:
HsqlUnsupportedOperationException - if an MD5 digest algorithm is not available through the java.security.MessageDigest spi or the requested encoding is not available
RuntimeException

digestString

public static byte[] digestString(String string,
                                  String encoding)
                           throws RuntimeException
Retrieves a byte sequence representing the MD5 digest of the specified character sequence, using the specified encoding to first convert the character sequence into a byte sequence. If the specified encoding is null, then ISO-8859-1 is assumed.

Parameters:
string - the string to digest.
encoding - the character encoding.
Returns:
the digest as an array of 16 bytes.
Throws:
HsqlUnsupportedOperationException - if an MD5 digest algorithm is not available through the java.security.MessageDigest spi or the requested encoding is not available
RuntimeException

digestBytes

public static final byte[] digestBytes(byte[] data)
                                throws RuntimeException
Retrieves a byte sequence representing the MD5 digest of the specified byte sequence.

Parameters:
data - the data to digest.
Returns:
the MD5 digest as an array of 16 bytes.
Throws:
HsqlUnsupportedOperationException - if an MD5 digest algorithm is not available through the java.security.MessageDigest spi
RuntimeException


Copyright © 2001 - 2004 HSQL Development Group. All Rights Reserved.