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 srcStr)
sha
return hash("SHA-1", srcStr);
StringSHA1(String str)
SHA
return encrypt(str, "SHA1");
StringSHA1(String str)
SHA
MessageDigest mDigest = MessageDigest.getInstance("SHA-1");
mDigest.reset();
mDigest.update(str.getBytes("UTF-8"));
Formatter f = new Formatter();
for (byte b : mDigest.digest())
    f.format("%02x", b);
return f.toString();
Stringsha1(String str)
sha
if (str == null || str.length() == 0) {
    return null;
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try {
    MessageDigest mdTemp = MessageDigest.getInstance("SHA1");
    mdTemp.update(str.getBytes());
    byte[] md = mdTemp.digest();
...
Stringsha1(String str)
sha
try {
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    md.update(str.getBytes());
    byte[] b = md.digest();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < b.length; i++) {
        int v = (int) b[i];
        v = v < 0 ? 0x100 + v : v;
...
Stringsha1(String str)
sha
MessageDigest sha = MessageDigest.getInstance("SHA");
sha.update(str.getBytes("utf8"));
byte[] bytes = sha.digest();
StringBuilder ret = new StringBuilder(bytes.length << 1);
for (int i = 0; i < bytes.length; i++) {
    ret.append(Character.forDigit((bytes[i] >> 4) & 0xf, 16));
    ret.append(Character.forDigit(bytes[i] & 0xf, 16));
return ret.toString();
byte[]sha1(String str)
Calculate a SHA-1 hash from the specified string.
try {
    MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
    return sha1.digest(str.getBytes(Charset.forName("UTF-8")));
} catch (NoSuchAlgorithmException e) {
    throw new RuntimeException("Must support SHA-1", e);
Stringsha1(String str)
sha
try {
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    byte[] bytes = md.digest(str.getBytes("utf-8"));
    StringBuilder sb = new StringBuilder(bytes.length * 2);
    for (int i = 0; i < bytes.length; i++) {
        sb.append(String.format("%02x", bytes[i]));
    return sb.toString();
...
Stringsha1(String str)
sha
try {
    StringBuffer sb = new StringBuffer();
    MessageDigest md = MessageDigest.getInstance("sha1");
    md.update(str.getBytes());
    byte[] msg = md.digest();
    for (byte b : msg) {
        sb.append(String.format("%02x", b));
    return sb.toString();
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
return null;
Stringsha1(String str)
sha
String sha1 = encode(str, "SHA-1");
return sha1;