md5 byte array - Java Security

Java examples for Security:MD5

Description

md5 byte array

Demo Code


//package com.java2s;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte[] bytes = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(java.util.Arrays.toString(md5(bytes)));
    }//from   w  w w  .j a v  a 2 s.  c o  m

    private static byte[] md5(byte[] bytes) {
        MessageDigest dist = null;
        byte[] result = null;
        try {
            dist = MessageDigest.getInstance("MD5");
            result = dist.digest(bytes);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException(e);
        }
        return result;
    }
}

Related Tutorials