1 17 18 19 package org.apache.catalina.util; 20 21 22 32 33 public final class MD5Encoder { 34 35 36 38 39 private static final char[] hexadecimal = 40 {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 41 'a', 'b', 'c', 'd', 'e', 'f'}; 42 43 44 46 47 53 public String encode( byte[] binaryData ) { 54 55 if (binaryData.length != 16) 56 return null; 57 58 char[] buffer = new char[32]; 59 60 for (int i=0; i<16; i++) { 61 int low = (int) (binaryData[i] & 0x0f); 62 int high = (int) ((binaryData[i] & 0xf0) >> 4); 63 buffer[i*2] = hexadecimal[high]; 64 buffer[i*2 + 1] = hexadecimal[low]; 65 } 66 67 return new String (buffer); 68 69 } 70 71 72 } 73 74 | Popular Tags |