Android Hash Code Calculate hash(String s, String algorithm)

Here you can find the source of hash(String s, String algorithm)

Description

hash

Declaration

private static String hash(String s, String algorithm) 

Method Source Code

//package com.java2s;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    private static String hash(String s, String algorithm) {
        String result = s;//ww  w  .j a v a 2  s  .  c o  m
        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) {
            // No way...
        }
        return result;
    }
}

Related

  1. hash(File file, String algorithm)
  2. hash(String input, String algorithm)
  3. hash(String password)
  4. hash(char[] pin, byte[] salt)
  5. hash(int seed, Object o)
  6. hash(int seed, boolean x)
  7. hash(int seed, int x)