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