Class MD5
- java.lang.Object
-
- org.hsqldb.lib.MD5
-
public final class MD5 extends java.lang.ObjectProvides 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 FUNCTION MD5(VARCHAR(100)) RETURNS VARCHAR(16) LANGUAGE JAVA EXTERNAL NAME "org.hsqldb.lib.MD5.encode" -- 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.9.0
-
-
Constructor Summary
Constructors Constructor and Description MD5()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static byte[]digest(byte[] data)Retrieves a byte sequence representing the MD5 digest of the specified byte sequence.static java.lang.Stringdigest(java.lang.String string)Retrieves a hexidecimal character sequence representing the MD5 digest of the specified character sequence, using the ISO-8859-1 encodingstatic byte[]digest(java.lang.String string, java.lang.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 java.lang.Stringencode(java.lang.String string, java.lang.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.
-
-
-
Method Detail
-
encode
public static final java.lang.String encode(java.lang.String string, java.lang.String encoding) throws java.lang.RuntimeExceptionRetrieves 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 availablejava.lang.RuntimeException
-
digest
public static final java.lang.String digest(java.lang.String string) throws java.lang.RuntimeExceptionRetrieves a hexidecimal character sequence representing the MD5 digest of the specified character sequence, using the ISO-8859-1 encoding- Parameters:
string- the string to encode.- 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 spijava.lang.RuntimeException
-
digest
public static final byte[] digest(java.lang.String string, java.lang.String encoding) throws java.lang.RuntimeExceptionRetrieves 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 availablejava.lang.RuntimeException
-
digest
public static final byte[] digest(byte[] data) throws java.lang.RuntimeExceptionRetrieves 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 spijava.lang.RuntimeException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG