Sep 14, 2018

Hash String via SHA-256 in Java

You can use Guava, as the following:

Hashing.sha256().hashString("MyStringToBeHashed", Charsets.UTF_8);

Maven dependency:

<dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>17.0</version>
            <type>jar</type>
</dependency>