Android Utililty Methods Hash Code Calculate

List of utility methods to do Hash Code Calculate

Description

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

Method

Stringhash(File file, String algorithm)
hash
try {
    MessageDigest md = MessageDigest.getInstance(algorithm);
    InputStream is = new FileInputStream(file);
    byte[] buffer = new byte[8192];
    int read = 0;
    while ((read = is.read(buffer)) > 0) {
        md.update(buffer, 0, read);
    is.close();
    byte[] messageDigest = md.digest();
    return toHexString(messageDigest);
} catch (NoSuchAlgorithmException e) {
    throw new IllegalArgumentException(e);
Stringhash(String input, String algorithm)
hash
try {
    MessageDigest md = MessageDigest.getInstance(algorithm);
    byte[] messageDigest = md.digest(input.getBytes());
    return toHexString(messageDigest);
} catch (NoSuchAlgorithmException e) {
    throw new IllegalArgumentException(e);
byte[]hash(String password)
hash
MessageDigest digest = null;
try {
    digest = java.security.MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
digest.update(password.getBytes());
byte messageDigest[] = digest.digest();
...
Stringhash(String s, String algorithm)
hash
String result = s;
try {
    MessageDigest digest = MessageDigest.getInstance(algorithm);
    byte[] bytes = digest.digest(s.getBytes());
    BigInteger biggie = new BigInteger(1, bytes);
    result = String
            .format("%0" + (bytes.length << 1) + "x", biggie);
} catch (NoSuchAlgorithmException e) {
...
byte[]hash(char[] pin, byte[] salt)
hash
PBEKeySpec spec = new PBEKeySpec(pin, salt, ROUNDS, KEY_LEN);
Arrays.fill(pin, Character.MIN_VALUE);
try {
    SecretKeyFactory skf = SecretKeyFactory
            .getInstance(KEY_ALGORITHM);
    return skf.generateSecret(spec).getEncoded();
} finally {
    spec.clearPassword();
...
inthash(int seed, Object o)
hash
return firstTerm(seed) + (o == null ? 0 : o.hashCode());
inthash(int seed, boolean x)
hash
return firstTerm(seed) + (x ? 0 : 1);
inthash(int seed, int x)
hash
return firstTerm(seed) + x;
byte[]hash2jsonBytes(Map hash)
hashjson Bytes
String result = null;
JSONObject json = new JSONObject(hash);
try {
    result = json.toString(2);
} catch (JSONException e) {
    e.printStackTrace();
return result.getBytes();
...
inthashBitmap(Bitmap bitmap)
hash Bitmap
int hash_result = 0;
int w = bitmap.getWidth();
int h = bitmap.getHeight();
hash_result = (hash_result << 7) ^ h;
hash_result = (hash_result << 7) ^ w;
for (int pixel = 0; pixel < 20; ++pixel) {
    int x = (pixel * 50) % w;
    int y = (pixel * 100) % h;
...