This was originally a rather straight re-implementation of the reference implementation given in RFC1321 by RSA. It passes the MD5 test suite as defined in RFC1321.
Many optimizations made by Timothy W Macinta. Reduced time to checksum a test file in Java alone to roughly half the time taken compared with java.security.MessageDigest (within an intepretter). Also added an optional native method to reduce the time even further. See http://www.twmacinta.com/myjava/fast_md5.php for further information on the time improvements achieved.
Some bug fixes also made by Timothy W Macinta.
Please note: I (Timothy Macinta) have put this code in the com.twmacinta.util package only because it came without a package. I was not the the original author of the code, although I did optimize it (substantially) and fix some bugs.
This Java class has been derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm and its reference implementation.
This class will attempt to use a native method to quickly compute checksums when the appropriate native library is available. On Linux, this library should be named "MD5.so" and on Windows it should be named "MD5.dll". The code will attempt to locate the library in the following locations in the order given:
If the library is not found, the code will fall back to the default (slower) Java code.
As a side effect of having the code search for the native library, SecurityExceptions might be thrown on JVMs that have a restrictive SecurityManager. The initialization code attempts to silently discard these exceptions and continue, but many SecurityManagers will attempt to notify the user directly of all SecurityExceptions thrown. Consequently, the code has provisions for skipping the search for the native library. Any of these provisions may be used to skip the search as long as they are performed before the first instance of a com.twmacinta.util.MD5 object is constructed (note that the convenience stream objects will implicitly create an MD5 object).
The first option is to set the system property "com.twmacinta.util.MD5.NO_NATIVE_LIB" to "true" or "1". Unfortunately, SecurityManagers may also choose to disallow system property setting, so this won't be of use in all cases.
The second option is to call com.twmacinta.util.MD5.initNativeLibrary(false) before any MD5 objects are constructed.
@author Santeri Paavolainen
MD5
...
Note: even if standard Java 1.1 APIs already provide a MD5 implementation, this class is used on those Java runtime environments (like Kaffe) where the package java.security
is highly improbable to be found.
@author Stefano Mazzocchi
@version $Id: MD5.java 264148 2005-08-29 14:21:04Z henning $
@deprecated Use the java.security package.
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 @author boucherb@users.sourceforge.net @version 1.9.0 @since 1.9.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|