Java SHA1 sha1Hash(String toHash)

Here you can find the source of sha1Hash(String toHash)

Description

sha Hash

License

Apache License

Declaration

public static String sha1Hash(String toHash) throws NoSuchAlgorithmException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static String sha1Hash(String toHash) throws NoSuchAlgorithmException {
        byte[] uniqueKey = toHash.getBytes();
        byte[] hash = null;
        hash = MessageDigest.getInstance("SHA1").digest(uniqueKey);
        StringBuilder hashString = new StringBuilder();
        for (int i = 0; i < hash.length; i++) {
            String hex = Integer.toHexString(hash[i]);
            if (hex.length() == 1) {
                hashString.append('0');
                hashString.append(hex.charAt(hex.length() - 1));
            } else
                hashString.append(hex.substring(hex.length() - 2));
        }/*from  w w w .j  ava  2  s .com*/
        return hashString.toString();
    }
}

Related

  1. sha1Hash(String input)
  2. sha1hash(String key)
  3. sha1Hash(String s)
  4. sha1Hash(String source)
  5. sha1Hash(String text)
  6. sha1Hash(String tohash)
  7. sha1HashHex(String data)
  8. sha1HashInt(String text)
  9. sha1Hex(byte[] bytes)