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 digester = new Digester("SHA-1");
byte[] message = "Hello World from Jasypt".getBytes();
// Creates a digest from a array of byte message.
byte[] digest = digester.digest(message);
System.out.println("Digest = " + new String(digest));
System.out.println("Digest = " + Arrays.toString(digest));
}
}
Latest posts by Wayan (see all)
- How do I create a generic class in Java? - January 1, 2021
- How do I convert java.util.TimeZone to java.time.ZoneId? - April 25, 2020
- How do I get a list of all TimeZones Ids using Java 8? - April 25, 2020