Code example for BigInteger

Methods: toString

0
	public static String toSHA1(String input) {
        try { 
            int lenght = 40; // 64 from SHA-256
            MessageDigest sha = MessageDigest.getInstance("SHA-1");
            byte[] messageDigest = sha.digest(input.getBytes());
            BigInteger number = new BigInteger(1, messageDigest);
            String out = number.toString(16);
            if (out.length() < lenght) {
                char[] charArray = new char[lenght];
                Arrays.fill(charArray, '0'); 
                out.getChars(0, out.length(), charArray, lenght - out.length());
                out = new String(charArray);
            } 
            return out;
        } catch (Exception ex) {
           ex.printStackTrace();
        } 
        return null; 
	}