Thursday, November 15, 2012

Create MD5 and SHA checksums easier with EzDigest (JAVA)

Creating a simple MD5 checksum in Java is a multistep process. I created a simple java class called EzDigest that should make the process much simpler.

JavaUtils JAR and source download on SourceForge
JavaUtils JAR and source download on GitHub

EzDigest can handle the following one way message digests:
MD2
MD5
SHA
SHA1
SHA256
SHA384
SHA512

It currently the only member of the JavaUtils package. If you have any ideas or requests for similar utilities (or additional digests/hashes), let me know in the comments!

Here is how to use the JavaUtils class with NetBeans:

Select Properties of your project:

Under Libraries, select Add JAR/Folder

Select the javautils.jar, and click Choose.

Then, click OK.

Now, you're ready to use JavaUtils. Below is an example of its use:

import java.security.NoSuchAlgorithmException;
import javautils.digest.EzDigest;

public class Testing {

    public static void main(String[] args) {
        try {
            System.out.println("SHA256: " + EzDigest.getSHA256String("Test"));
            System.out.println("MD5 : " + EzDigest.getMD5String("Test"));
        } catch (NoSuchAlgorithmException ex) {
            System.out.println(ex.getCause());
        }
    }
}

The output:

run:
SHA256: 532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25
MD5 : 0cbc6611f5540bd0809a388dc95a615b
BUILD SUCCESSFUL (total time: 0 seconds)

No comments:

Post a Comment