Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 76   Methods: 3
NCLOC: 39   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MD5.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: MD5.java 541508 2007-05-25 01:54:12Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.util;
 21   
 22    import java.security.MessageDigest;
 23    import java.security.NoSuchAlgorithmException;
 24   
 25    /**
 26    * TODO: Not used. Remove?
 27    * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $
 28    */
 29    public class MD5 {
 30    private static String[] hex = {"0", "1", "2", "3", "4", "5", "6", "7",
 31    "8", "9", "a", "b", "c", "d", "e", "f"};
 32   
 33  0 public static String md(String pswd) {
 34  0 MessageDigest md;
 35  0 String digestString = "";
 36   
 37  0 try {
 38  0 md = MessageDigest.getInstance("MD5");
 39  0 md.update(pswd.getBytes("utf-8"));
 40   
 41  0 byte[] digest = md.digest();
 42   
 43  0 digestString = byteArrayToHexString(digest);
 44    } catch (NoSuchAlgorithmException e) {
 45  0 System.out.println("MD5 not supported.");
 46  0 e.printStackTrace(System.err);
 47    } catch (Exception e) {
 48  0 e.printStackTrace(System.err);
 49    }
 50   
 51  0 return digestString;
 52    }
 53   
 54  0 static String byteToHexString(byte b) {
 55  0 int n = b;
 56   
 57  0 if (n < 0) {
 58  0 n = 256 + n;
 59    }
 60   
 61  0 int d1 = n / 16;
 62  0 int d2 = n % 16;
 63   
 64  0 return hex[d1] + hex[d2];
 65    }
 66   
 67  0 static String byteArrayToHexString(byte[] b) {
 68  0 StringBuffer result = new StringBuffer(b.length * 2);
 69   
 70  0 for (int i = 0; i < b.length; ++i) {
 71  0 result.append(byteToHexString(b[i]));
 72    }
 73   
 74  0 return result.toString();
 75    }
 76    }