get MD5 byte array from String - Java Security

Java examples for Security:MD5

Description

get MD5 byte array from String

Demo Code


//package com.java2s;

import java.security.MessageDigest;

public class Main {
    public static void main(String[] argv) throws Exception {
        String input = "java2s.com";
        System.out.println(java.util.Arrays.toString(getMD5(input)));
    }/*from  www.  j a  v a  2s.c  om*/

    private static byte[] getMD5(String input) {
        try {
            byte[] bytesOfMessage = input.getBytes("UTF-8");
            MessageDigest md = MessageDigest.getInstance("MD5");
            return md.digest(bytesOfMessage);
        } catch (Exception e) {
            return null;
        }
    }
}

Related Tutorials