package com.secdec.codedx.util;

/**************************************************************************
 * Copyright (c) 2014 Applied Visions, Inc. All Rights Reserved.
 * Author: Applied Visions, Inc. - Chris Ellsworth
 * Project: Code Dx
 * SubSystem: com.secdec.codedx.util
 * FileName: HashUtil.java
 *************************************************************************/

        import java.security.MessageDigest;
        import java.security.NoSuchAlgorithmException;
        import java.util.Formatter;

/**
 * @author Chris Ellsworth
 *
 */
public class HashUtil {
//    public static String toMd5(String input) {
//        String toReturn = null;
//        try {
//            byte[] digest = MessageDigest.getInstance("MD5").digest(input.getBytes());
//            StringBuilder hashBuilder = new StringBuilder();
//            for (byte b : digest) {
//                hashBuilder.append(String.format("%x", b));
//            }
//            toReturn = hashBuilder.toString();
//        } catch (NoSuchAlgorithmException exc) {
//            throw new CodeDxException(exc);
//        }
//        return toReturn;
//    }

    public static byte[] getSHA1(byte[] input) {

        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            md.reset();
            return md.digest(input);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    public static String toHexString(byte[] bytes) {
        return toHexString(bytes, "");
    }

    public static String toHexString(byte[] bytes, String sep) {
        Formatter f = new Formatter();
        for (int i = 0; i < bytes.length; i++) {
            f.format("%02x", bytes[i]);
            if (i < bytes.length - 1) {
                f.format(sep);
            }
        }
        String result = f.toString();
        f.close();
        return result;
    }
}
@@ -30,369 +30,8 @@
 l;%0A%0A
-/**************************************************************************%0A * Copyright (c) 2014 Applied Visions, Inc. All Rights Reserved.%0A * Author: Applied Visions, Inc. - Chris Ellsworth%0A * Project: Code Dx%0A * SubSystem: com.secdec.codedx.util%0A * FileName: HashUtil.java%0A *************************************************************************/%0A%0A        
 impo
@@ -62,24 +62,16 @@
 Digest;%0A
-        
 import j
@@ -109,24 +109,16 @@
 eption;%0A
-        
 import j
@@ -149,628 +149,113 @@
 %0A * 
-@author Chris Ellsworth%0A *%0A */%0Apublic class HashUtil %7B%0A//    public static String toMd5(String input) %7B%0A//        String toReturn = null;%0A//        try %7B%0A//            byte%5B%5D digest = MessageDigest.getInstance(%22MD5%22).digest(input.getBytes());%0A//            StringBuilder hashBuilder = new StringBuilder();%0A//            for (byte b : digest) %7B%0A//                hashBuilder.append(String.format(%22%25x%22, b));%0A//            %7D%0A//            toReturn = hashBuilder.toString();%0A//        %7D catch (NoSuchAlgorithmException exc) %7B%0A//            throw new CodeDxException(exc);%0A//        %7D%0A//        return toReturn;%0A//    %7D%0A%0A    
+Contains utilities for dealing with Hashes%0A *%0A * @author Samuel Johnson%0A *%0A */%0Apublic class HashUtil %7B%0A%0A%09
 publ
@@ -300,34 +300,19 @@
  %7B%0A%0A
-        try %7B%0A            
+%09%09try %7B%0A%09%09%09
 Mess
@@ -366,44 +366,26 @@
 %22);%0A
-            md.reset();%0A            
+%09%09%09md.reset();%0A%09%09%09
 retu
@@ -405,24 +405,18 @@
 input);%0A
-        
+%09%09
 %7D catch 
@@ -446,28 +446,19 @@
 on e) %7B%0A
-            
+%09%09%09
 throw ne
@@ -484,29 +484,17 @@
 e);%0A
-        %7D%0A    %7D%0A%0A    
+%09%09%7D%0A%09%7D%0A%0A%09
 publ
@@ -538,24 +538,18 @@
 ytes) %7B%0A
-        
+%09%09
 return t
@@ -575,19 +575,13 @@
 %22);%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 publ
@@ -637,24 +637,18 @@
  sep) %7B%0A
-        
+%09%09
 Formatte
@@ -670,24 +670,18 @@
 tter();%0A
-        
+%09%09
 for (int
@@ -713,28 +713,19 @@
  i++) %7B%0A
-            
+%09%09%09
 f.format
@@ -744,28 +744,19 @@
 es%5Bi%5D);%0A
-            
+%09%09%09
 if (i %3C 
@@ -779,71 +779,38 @@
 ) %7B%0A
-                f.format(sep);%0A            %7D%0A        %7D%0A        
+%09%09%09%09f.format(sep);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09
 Stri
@@ -835,24 +835,18 @@
 ring();%0A
-        
+%09%09
 f.close(
@@ -852,16 +852,10 @@
 ();%0A
-        
+%09%09
 retu
@@ -869,11 +869,8 @@
 lt;%0A
-    
+%09
 %7D%0A%7D

Clean up code and documentation