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 s)
sha
try {
    MessageDigest digest = MessageDigest.getInstance("SHA-1");
    digest.update(s.getBytes());
    byte messageDigest[] = digest.digest();
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < messageDigest.length; i++) {
        hexString.append(Integer.toHexString((0xFF & messageDigest[i]) | 0x100).substring(1));
    return hexString.toString();
} catch (NoSuchAlgorithmException e) {
    return "";
Stringsha1(String s)
sha
try {
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    md.update(s.getBytes());
    return bytes2hex(md.digest());
} catch (Exception ex) {
    ex.printStackTrace();
return null;
...
Stringsha1(String s)
sha
return digest(s, DIGEST_SHA1);
Stringsha1(String s)
sha
MessageDigest md = null;
try {
    md = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException("sha1 not supported by plattform");
try {
    byte[] result = md.digest(s.getBytes("UTF-8"));
...
Stringsha1(String s)
sha
MessageDigest mDigest;
try {
    mDigest = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
byte[] result = mDigest.digest(s.getBytes());
StringBuffer sb = new StringBuffer();
...
Stringsha1(String s)
sha
MessageDigest md = getMessageDigest("sha-1");
return bytes2HexString(md.digest(s.getBytes(StandardCharsets.UTF_8)));
Stringsha1(String s)
Computes the SHA1 sum of the given string.
try {
    return byteArrayToHexString(MessageDigest.getInstance("SHA").digest(s.getBytes("US-ASCII")));
} catch (NoSuchAlgorithmException | UnsupportedEncodingException nsae) {
    throw new RuntimeException(nsae);
Stringsha1(String src)
Calculates the SHA-1 digest and returns the value as a 40 character hex string.
try {
    md = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
md.update(src.getBytes(StandardCharsets.UTF_8));
return String.format("%040x", new BigInteger(1, md.digest()));
Stringsha1(String src)
sha
MessageDigest md = MessageDigest.getInstance("SHA1"); 
byte[] hashBytes = md.digest(src.getBytes());
BASE64Encoder b64e = new BASE64Encoder(); 
String hash = b64e.encode(hashBytes);
return hash;
Stringsha1(String src)
sha
MessageDigest md1 = null;
try {
    md1 = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
try {
    md1.update(src.getBytes("UTF-8"));
...