Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

public class Main {

    public static String multiMD5Hex(byte[] data) {
        return new String(Hex.encodeHex(multiMD5(data)));
    }

    public static byte[] multiMD5(byte[] data) {
        byte[] res = DigestUtils.md5(data);
        int headLength = res.length / 2;
        byte[] head = new byte[headLength];

        if (res.length > headLength) {
            byte[] tail = new byte[res.length - headLength];

            System.arraycopy(res, 0, head, 0, headLength);
            System.arraycopy(res, headLength, tail, 0, tail.length);
            head = DigestUtils.md5(head);
            tail = DigestUtils.md5(tail);
            res = new byte[head.length + tail.length];
            System.arraycopy(head, 0, res, 0, head.length);
            System.arraycopy(tail, 0, res, head.length, tail.length);
        }

        res = DigestUtils.md5(res);

        return res;
    }
}