/*
 * Copyright 2012 ToureNPlaner
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package de.tourenplaner.utils;

import org.jboss.netty.util.CharsetUtil;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author Christoph Haag, Sascha Meusel, Niklas Schnelle, Peter Vollmer
 */
public class SHA1 {

    private static String convertToHex(byte[] data) {
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            int halfbyte = (data[i] >>> 4) & 0x0F;
            int two_halfs = 0;
            do {
                if ((0 <= halfbyte) && (halfbyte <= 9)) buf.append((char) ('0' + halfbyte));
                else buf.append((char) ('a' + (halfbyte - 10)));
                halfbyte = data[i] & 0x0F;
            } while (two_halfs++ < 1);
        }
        return buf.toString();
    }

    public static String SHA1(String text)  {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        md.update(text.getBytes(CharsetUtil.UTF_8), 0, text.length());
        byte[] sha1hash = md.digest();
        return convertToHex(sha1hash);
    }
}
@@ -939,24 +939,30 @@
         
+final 
 StringBu
 ffer buf
@@ -957,67 +957,45 @@
 ngBu
-ffer buf = new StringBuffer();%0A        for (int i = 0; i %3C 
+ilder hexbuilder = new StringBuilder(
 data
@@ -1005,16 +1005,14 @@
 ngth
-; i++) %7B
+ * 2);
 %0A   
@@ -1020,336 +1020,159 @@
     
-    int halfbyte = (data%5Bi%5D %3E%3E%3E 4) & 0x0F;%0A            int two_halfs = 0;%0A            do %7B%0A                if ((0 %3C= halfbyte) && (halfbyte %3C= 9)) buf.append((char) ('0' + halfbyte));%0A                else buf.append((char) ('a' + (halfbyte - 10)));%0A                halfbyte = data%5Bi%5D & 0x0F;%0A            %7D while (two_halfs++ %3C 1
+for (byte b : data) %7B%0A            hexbuilder.append(Integer.toHexString((b %3E%3E%3E 4) & 0x0F));%0A            hexbuilder.append(Integer.toHexString(b & 0x0F)
 );%0A 
@@ -1199,11 +1199,18 @@
 urn 
-buf
+hexbuilder
 .toS

Use own toHex code which is better understandable