Java Utililty Methods SHA1

List of utility methods to do SHA1

Description

The list of methods to do SHA1 are organized into topic(s).

Method

Stringsha1(String input)
Return a string of 40 lower case hex characters.
String hexHash = null;
try {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    md.update(input.getBytes());
    byte[] output = md.digest();
    hexHash = bytesToLowerCaseHex(output);
} catch (NoSuchAlgorithmException nsae) {
    throw new RuntimeException(nsae);
...
Stringsha1(String input)
sha
StringBuilder stringBuilder = new StringBuilder();
try {
    MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
    for (byte res : messageDigest.digest(input.getBytes())) {
        stringBuilder.append(Integer.toString((res & 0xff) + 0x100, 16).substring(1));
} catch (NoSuchAlgorithmException e) {
    throw new IllegalArgumentException("Hashing algorithms does not exist");
...
Stringsha1(String input)
sha
MessageDigest mDigest = MessageDigest.getInstance("SHA1");
byte[] result = mDigest.digest(input.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
    sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1));
return sb.toString();
Stringsha1(String input)
sha
MessageDigest sha1;
try {
    sha1 = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
    return null;
byte[] ret = sha1.digest(input.getBytes());
return byteArray2Hex(ret);
...
byte[]sha1(String input)
sha
try {
    MessageDigest mDigest = MessageDigest.getInstance("SHA1");
    return mDigest.digest(input.getBytes());
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
return null;
Stringsha1(String input)
sha
return hash(input, "SHA1");
byte[]sha1(String input, String encoding)
sha
return digest(input, "sha-1", encoding);
Stringsha1(String message)
sha
try {
    byte[] buffer = message.getBytes("UTF-8");
    MessageDigest md = MessageDigest.getInstance("SHA1");
    md.update(buffer);
    byte[] digest = md.digest();
    char[] hash = new char[40];
    for (int i = 0, n = 0; i < digest.length; i++) {
        byte aux = digest[i];
...
byte[]sha1(String param)
sha
MessageDigest SHA = null;
try {
    SHA = MessageDigest.getInstance("SHA-1");
    SHA.reset();
    SHA.update(param.getBytes("UTF-8"));
} catch (Exception e) {
    System.err.println(e);
return SHA.digest();
Stringsha1(String raw)
sha
try {
    MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
    messageDigest.update(raw.getBytes());
    return bytesToHexStr(messageDigest.digest());
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException("sha1 encryption error", e);