Android Utililty Methods SHA1 Hash Create

List of utility methods to do SHA1 Hash Create

Description

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

Method

Stringsha1(String ori)
sha
try {
    MessageDigest md = MessageDigest.getInstance("sha1");
    md.update(ori.getBytes(), 0, ori.length());
    BigInteger i = new BigInteger(1, md.digest());
    return String.format("%1$040x", i);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
    return ori;
...
Stringsha1(String ori)
sha
try {
    MessageDigest md = MessageDigest.getInstance("sha1");
    md.update(ori.getBytes(), 0, ori.length());
    BigInteger i = new BigInteger(1, md.digest());
    return String.format("%1$040x", i);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
    return ori;
...
Stringsha1(String s)
SHA1 algorithm
return encrypt(s, "SHA-1");
Stringsha1(String s)
sha
return hash(s, "SHA1");
StringcomputeHashSHA1(final String text)
Returns a hash value for a string using SHA-1 algorithm
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(text.getBytes(), 0, text.length());
byte hashData[] = md.digest();
StringBuilder sb = new StringBuilder(hashData.length * 2);
for (int i = 0; i < hashData.length; i++) {
    int b = (0xFF & hashData[i]);
    if (b <= 0xF)
        sb.append('0');
...
StringcomputeSHAHash(String password)
compute SHA Hash
MessageDigest digest = null;
try {
    digest = MessageDigest.getInstance("SHA-1");
} catch (Exception e) {
    e.printStackTrace();
digest.reset();
byte[] data = digest.digest(password.getBytes());
...
StringgetSHA1CertFingerprint(Context ctx)
get SHA Cert Fingerprint
try {
    Signature[] sigs = ctx.getPackageManager().getPackageInfo(
            ctx.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
    if (sigs.length == 0) {
        return "ERROR: NO SIGNATURE.";
    } else if (sigs.length > 1) {
        return "ERROR: MULTIPLE SIGNATURES";
    byte[] digest = MessageDigest.getInstance("SHA1").digest(
            sigs[0].toByteArray());
    StringBuilder hexString = new StringBuilder();
    for (int i = 0; i < digest.length; ++i) {
        if (i > 0) {
            hexString.append(":");
        byteToString(hexString, digest[i]);
    return hexString.toString();
} catch (PackageManager.NameNotFoundException ex) {
    ex.printStackTrace();
    return "(ERROR: package not found)";
} catch (NoSuchAlgorithmException ex) {
    ex.printStackTrace();
    return "(ERROR: SHA1 algorithm not found)";
StringSHA1(String text)
Converts a String into a SHA-1 hash.
return hashAlgorithm("SHA-1", text);
byte[]shaByte(String in)
Returns a byte array representation of the hash of a string input using the SHA1 hashing algorithm.
return digestByte("SHA", in.getBytes());
byte[]shaByte(byte[] in)
Returns a byte array representation of the hash of a byte array input using the SHA1 hashing algorithm.
return digestByte("SHA", in);