Write a program to generate SHA-1 hash.


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Scanner;
import org.apache.commons.codec.binary.*;
public class PracSHA { //name of your class file must be same
    public static void main(String[] args) throws NoSuchAlgorithmException {
            String text;
             System.out.println("Enter the Text you want to encode in SHA :");
            Scanner scan = new Scanner(System.in);
            text = scan.next();
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(text.getBytes());
            byte encode[];
            encode = md.digest();

            System.out.println(Hex.encodeHexString(encode));
    }
}

Output :