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.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 an array of byte message.
byte[] digest = digester.digest(message);
System.out.println("Digest = " + new String(digest));
System.out.println("Digest = " + Arrays.toString(digest));
}
}
Maven Dependencies
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.3</version>
</dependency>
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024