Android Utililty Methods String Hash

List of utility methods to do String Hash

Description

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

Method

Stringhash(String text, String algorithm)
hash
try {
    MessageDigest md = MessageDigest.getInstance(algorithm);
    md.update(text.getBytes("iso-8859-1"), 0, text.length());
    byte[] hashBytes = md.digest();
    return convertToHex(hashBytes);
} catch (Exception e) {
return "";
...
StringhashKeyForDisk(String key)
hash Key For Disk
String cacheKey;
try {
    final MessageDigest mDigest = MessageDigest.getInstance("MD5");
    mDigest.update(key.getBytes());
    cacheKey = bytesToHexString(mDigest.digest());
} catch (NoSuchAlgorithmException e) {
    cacheKey = String.valueOf(key.hashCode());
return cacheKey;
HashtablehashIt(String s)
hash It
Hashtable ht = new Hashtable();
int i = 0, a = 0, b = 0, c = 0;
if (s.length() > 0) {
    while (i < s.length()) {
        a = i;
        while (s.charAt(i) != '=' && i < s.length()) {
            i++;
        b = i;
        while (s.charAt(i) != '&' && i < (s.length() - 1)) {
            i++;
        if (i < (s.length() - 1)) {
            c = i;
        } else {
            c = i + 1;
        ht.put(s.substring(a, b), s.substring(b + 1, c));
        i++;
return ht;
StringgenerateHash(String pText)
generate Hash
String hashValue = null;
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.reset();
md.update(pText.getBytes("ASCII"));
hashValue = encodeHex(md.digest());
return hashValue;
StringhashAlgorithm(String hash, String text)
Converts a String into a specified hash.
MessageDigest md;
byte[] sha1hash = new byte[40];
md = MessageDigest.getInstance(hash);
md.update(text.getBytes("iso-8859-1"), 0, text.length());
sha1hash = md.digest();
return convertToHex(sha1hash);