scrapes / ILO2-Standalone-Remote-Console

ILO2 Remote Console as Standalone version
49 stars 16 forks source link

Use java's MD5 implementation #1

Closed fridtjof closed 5 years ago

fridtjof commented 6 years ago

Using the test strings from RFC 1321, I tested VMD5 for equivalence with Java's MessageDigest MD5 implementation.

import com.hp.ilo2.remcons.VMD5;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public class TestMD5 {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        VMD5 vmd = new VMD5();

        boolean equal = true;

        String[] testStrings = {
                "",
                "a",
                "abc",
                "message digest",
                "abcdefghijklmnopqrstuvwxyz",
                "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
                "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
        };

        for (String test : testStrings) {
            md.reset();
            md.update(test.getBytes());

            vmd.init();
            vmd.update(test.getBytes());
            if (!Arrays.equals(md.digest(), vmd.digest())) {
                equal = false;
                break;
            }
        }

        if (equal)
            System.out.println("Implementations match!");
    }
}

As this program will say, the implementations match. Therefore, VMD5 can be replaced with Java's MD5.

I did not find out yet whether HP's RC4 implementation can be replaced with Java's implementation, but that's for another day.