How do I create a message digest?

Category: org.jasypt, viewed: 1608 time(s).

Creating a digest of a string message can be easily done using the general digester class Digester. First we need to get an instance of Digester, we call the class constructor and pass SHA-1 as the algorithm.

After having a Digester instance we create the message digest by executing or calling the Digester.digest(byte[] binary) method of this class.

package org.kodejava.example.jasypt;

import org.jasypt.util.digest.Digester;

import java.util.Arrays;

public class DigesterDemo {
    public static void main(String[] args) {
        //
        // Creates a new instance of Digester, using the SHA-1 algorithm.
        //
        Digester digister = new Digester("SHA-1");

        byte[] message = "Hello World from Jasypt".getBytes();
        
        //
        // Creates a disgest from a array of byte message.
        //
        byte[] digest = digister.digest(message);
        
        System.out.println("Digest = " + new String(digest));
        System.out.println("Digest = " + Arrays.toString(digest));
    }
}
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Uncensored Newsgroups
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Java Training

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats