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

byte[]sha1(byte[] bytes)
Performs an SHA-1 hash
try {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    return md.digest(bytes);
} catch (NoSuchAlgorithmException e) {
    throw new InternalError("SHA-1 not supported on this platform");
byte[]SHA1(byte[] bytes)
SHA
return digest("SHA-1", bytes);
StringSHA1(byte[] convertme)
SHA
MessageDigest md;
try {
    md = MessageDigest.getInstance("SHA-1");
    return byteArray2Hex(md.digest(convertme));
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
return "";
...
byte[]sha1(byte[] data)
Gera resumo em algoritimo SHA1
try {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    md.update(data);
    return md.digest();
} catch (Exception e) {
    e.printStackTrace();
    return null;
byte[]sha1(byte[] data)
sha
MessageDigest md = MessageDigest.getInstance("SHA-1");
byte[] sha1Hash = new byte[20];
byte[] id = new byte[8]; 
sha1Hash = md.digest(data);
System.arraycopy(sha1Hash, 0, id, 0, 8);
for (int i = 20; i < id.length; i++) {
    id[i] = 0;
return id;
Stringsha1(byte[] data)
Compute a SHA-1 hash using Java built-in MessageDigest, and format the result in hex.
try {
    MessageDigest md = MessageDigest.getInstance("sha-1", "SUN");
    byte[] sign = md.digest(data);
    return arraytohexstring(sign);
} catch (NoSuchAlgorithmException | NoSuchProviderException imp) {
    throw new RuntimeException(imp);
byte[]sha1(byte[] data)
sha
try {
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    md.update(data);
    return md.digest();
} catch (GeneralSecurityException e) {
    throw new ProviderException(e.getMessage());
StringSHA1(byte[] data)
SHA-1 encrypt method
MessageDigest md;
try {
    md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
    return null;
md.update(data);
byte[] encdata = md.digest();
...
byte[]sha1(byte[] input)
sha
return digest(input, SHA1, null, 1);
byte[]sha1(byte[] input)
Compute the sha1 hash of the input catching all the irritating exceptions for you
return getDigest("SHA-1").digest(input);