Android String Hash generateHash(String pText)

Here you can find the source of generateHash(String pText)

Description

generate Hash

License

Open Source License

Declaration

public static String generateHash(String pText) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.MessageDigest;

public class Main {
    private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

    public static String generateHash(String pText) throws Exception {
        String hashValue = null;/*from  ww  w .ja v a2 s  .  c o  m*/
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.reset();
        md.update(pText.getBytes("ASCII"));
        hashValue = encodeHex(md.digest());
        return hashValue;
    }

    private static String encodeHex(byte[] pData) {
        int l = pData.length;

        char[] out = new char[l << 1];

        // two characters form the hex value.
        for (int i = 0, j = 0; i < l; i++) {
            out[j++] = DIGITS[(0xF0 & pData[i]) >>> 4];
            out[j++] = DIGITS[0x0F & pData[i]];
        }

        return new String(out);
    }
}

Related

  1. hash(String text, String algorithm)
  2. hashKeyForDisk(String key)
  3. hashIt(String s)
  4. hashAlgorithm(String hash, String text)