Commonly asked Data Structures and Algorithms Problems by big tech and different solution approaches with code in Java and C

Powered by Blogger.

Friday, June 2, 2017

Sha256 algorithm java


import java.io.*;
import java.security.MessageDigest;
import java.util.*;

public class Solution {

   public static void main(String[] args) {             Scanner ab=new Scanner(System.in);        String str=ab.next();        try            {

// create a instance of class with Sha 256 algo

        MessageDigest md=MessageDigest.getInstance("SHA-256");


        md.update(str.getBytes());

// will give hash code to array

         byte[] digest = md.digest();


            for (byte b : digest) {                System.out.printf("%02x", b);            } } catch (Exception ex) {            throw new RuntimeException(ex);        }    }

}

0 Comments:

Post a Comment

Stats