Java MD5

  • + 0 comments

    import java.io.; import java.util.; import java.math.BigInteger; import java.security.MessageDigest;

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    
        Scanner scn=new Scanner(System.in);
        String str=scn.nextLine();
        scn.close();
        String output="";
        try{
             MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] digest = md.digest(str.getBytes());
            BigInteger bigInteger = new BigInteger(1,digest);
    
            String hash = bigInteger.toString(16);
            while(hash.length() < 32){
                hash += "0" + hash;
            }
    
            output = hash;
            System.out.println(output);
        }catch(Exception e){
            System.out.println(e.getMessage());
    
        }
    
    }
    

    }