1 18 package com.Ostermiller.util; 19 20 import java.util.*; 21 import java.io.*; 22 23 class MD5Tests { 24 25 private static class TestCase { 26 private String md5; 27 private byte[] bytes; 28 public TestCase(String md5, byte[] bytes){ 29 this.md5 = md5; 30 this.bytes = bytes; 31 } 32 private void test() throws Exception { 33 String hashString = MD5.getHashString(bytes); 34 if (!md5.equals(hashString)){ 35 throw new Exception ("Failed test. Should be " + md5 + " was " + hashString + "."); 36 } 37 } 38 } 39 40 private static final TestCase[] testCases = new TestCase[]{ 41 new TestCase("d41d8cd98f00b204e9800998ecf8427e", new byte[]{}), 42 new TestCase("0cc175b9c0f1b6a831c399e269772661", new byte[]{'a'}), 43 new TestCase("900150983cd24fb0d6963f7d28e17f72", new byte[]{'a','b','c'}), 44 new TestCase("f96b697d7cb7938d525a2f31aaf161d0", new byte[]{'m','e','s','s','a','g','e',' ','d','i','g','e','s','t'}), 45 new TestCase("c3fcd3d76192e4007dfb496cca67e13b", new byte[]{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}), 46 new TestCase("d174ab98d277d9f5a5611c2c9f419d9f", new byte[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9'}), 47 new TestCase("57edf4a22be3c955ac49da2e2107b67a", new byte[]{'1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0','1','2','3','4','5','6','7','8','9','0'}), 48 }; 49 50 public static void main(String [] args){ 51 try { 52 for (int i=0; i<testCases.length; i++){ 53 testCases[i].test(); 54 } 55 } catch (Exception x){ 56 x.printStackTrace(System.err); 57 System.exit(1); 58 } 59 System.exit(0); 60 } 61 } 62 | Popular Tags |