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 data)
sha
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(data.getBytes());
StringBuffer buf = new StringBuffer();
byte[] bits = md.digest();
for (int i = 0; i < bits.length; i++) {
    int a = bits[i];
    if (a < 0)
        a += 256;
...
Stringsha1(String data)
Hashes a String using the SHA-1 algorithm and returns the result as a String of hexadecimal numbers.
return hash(data, SHA1);
Stringsha1(String data)
Creates a sha1 out from a given data.
try {
    return new String(encodeHex(MessageDigest.getInstance("SHA-1").digest(data.getBytes("UTF-8"))));
} catch (NoSuchAlgorithmException e) {
    throw new IllegalStateException(e);
} catch (UnsupportedEncodingException e) {
    throw new IllegalStateException(e);
Stringsha1(String data)
sha
return byte2hex(MessageDigest.getInstance("SHA-1").digest(data.getBytes()));
byte[]SHA1(String decript)
SHA
try {
    MessageDigest digest = java.security.MessageDigest.getInstance("SHA-1");
    digest.update(decript.getBytes());
    return digest.digest();
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
Stringsha1(String input)
sha
MessageDigest mDigest = null;
try {
    mDigest = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
    return "" + input.hashCode();
byte[] result = mDigest.digest(input.getBytes());
StringBuffer sb = new StringBuffer();
...
Stringsha1(String input)
sha
return encrypt(input, ENCRY_SHA);
Stringsha1(String input)
sha
try {
    MessageDigest crypt = MessageDigest.getInstance("SHA-1");
    crypt.reset();
    crypt.update(input.getBytes(StandardCharsets.UTF_8));
    return new BigInteger(1, crypt.digest()).toString(16);
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException("Could not generate SHA-1 hash", e);
Stringsha1(String input)
sha
if (input == null) {
    throw new NullPointerException("The input parameter must not be null.");
return encrypt(input, "SHA-1");
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();