Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to hash string in java

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.nio.charset.StandardCharsets;
import java.math.BigInteger;

public class CryptoHash {
  public static void main(String[] args) throws NoSuchAlgorithmException {
    MessageDigest md = MessageDigest.getInstance("SHA-256");
    String text = "Text to hash, cryptographically.";

    // Change this to UTF-16 if needed
    md.update(text.getBytes(StandardCharsets.UTF_8));
    byte[] digest = md.digest();

    String hex = String.format("%064x", new BigInteger(1, digest));
    System.out.println(hex);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: split on . in java 
Java :: Sample HashMap 
Java :: arc() method from the processing library 
Java :: how to disable the cors in spring boot 
Java :: hashmap put 
Java :: map.keyset 
Java :: spring cli version 
Java :: java add element to map 
Java :: check if input is empty java 
Java :: Big decimal example 
Java :: pythagoras method in java 
Java :: take a peice from array java 
Java :: javaparser 
Java :: The superclass "jakarta.servlet.http.HttpServlet" was not found on the Java Build Path 
Java :: GetMapping("/rest/v1/books") in spring rest api 
Java :: new in t arrray java 
Java :: search 
Java :: java file search recursive 
Java :: java stream loop through list 
Java :: replace everything before a character in java 
Java :: list of java 
Java :: java integer object to char 
Java :: pyramid pattern java 
Java :: spring boot send api request 
Java :: Java Add elements to a HashMap 
Java :: java to kotlin converter android studio 
Java :: example of a for loop 
Java :: list of list in java 
Java :: try catch in java 
Java :: java check if array element is null 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =