diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/testsuite/libjava.lang/md5test.java | |
download | cbb-gcc-4.6.4-upstream.tar.bz2 cbb-gcc-4.6.4-upstream.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libjava/testsuite/libjava.lang/md5test.java')
-rw-r--r-- | libjava/testsuite/libjava.lang/md5test.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/libjava/testsuite/libjava.lang/md5test.java b/libjava/testsuite/libjava.lang/md5test.java new file mode 100644 index 000000000..ffd0a93cf --- /dev/null +++ b/libjava/testsuite/libjava.lang/md5test.java @@ -0,0 +1,63 @@ +import java.security.*; + +class md5test { + + + // gnu-crypto/source/gnu/testlet/gnu/crypto/hash/TestOfMD5.java + + public static void main(String[] argv) { + String[] strings = { + "a", + "abc", + "message digest", + "abcdefghijklmnopqrstuvwxyz", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "12345678901234567890123456789012345678901234567890123456789012345678901234567890" + }; + + String[] expected = { + "0CC175B9C0F1B6A831C399E269772661", + "900150983CD24FB0D6963F7D28E17F72", + "F96B697D7CB7938D525A2F31AAF161D0", + "C3FCD3D76192E4007DFB496CCA67E13B", + "D174AB98D277D9F5A5611C2C9F419D9F", + "57EDF4A22BE3C955AC49DA2E2107B67A" + }; + + for (int i = 0; i < strings.length; i++) + testString(strings[i], expected[i]); + + } + + public static void testString(String string, String expected) { + + MessageDigest md=null; + try { + md = MessageDigest.getInstance("MD5"); + md.update(string.getBytes(), 0, string.length()); + String result = toString(md.digest()); + System.out.println(expected); + System.out.println(result); + if (!expected.equals(result)) + System.out.println("NOT EQUAL!"); + } catch (Exception x) { + x.printStackTrace(); + } + } + + public static String toString(byte[] ba) { + return toString(ba, 0, ba.length); + } + public static final String toString(byte[] ba, int offset, int length) { + char[] buf = new char[length * 2]; + for (int i = 0, j = 0, k; i < length; ) { + k = ba[offset + i++]; + buf[j++] = HEX_DIGITS[(k >>> 4) & 0x0F]; + buf[j++] = HEX_DIGITS[ k & 0x0F]; + } + return new String(buf); + } + + private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray(); + +} |