Android SHA1 Hash Create computeSHAHash(String password)

Here you can find the source of computeSHAHash(String password)

Description

compute SHA Hash

Declaration

public final static String computeSHAHash(String password)
            throws Exception 

Method Source Code

//package com.java2s;

import java.security.MessageDigest;

import android.util.Base64;

public class Main {
    public final static String computeSHAHash(String password)
            throws Exception {
        MessageDigest mdSha1 = null;
        String SHAHash;// w ww  .j a  v  a  2 s . c o m

        mdSha1 = MessageDigest.getInstance("SHA-1");

        mdSha1.update(password.getBytes("ASCII"));

        byte[] data = mdSha1.digest();

        SHAHash = convertToHex(data);

        return SHAHash;
    }

    private static String convertToHex(byte[] data)
            throws java.io.IOException {

        StringBuffer sb = new StringBuffer();
        String hex = null;

        hex = Base64
                .encodeToString(data, 0, data.length, Base64.NO_PADDING);

        sb.append(hex);

        return sb.toString();
    }
}

Related

  1. shaByte(byte[] in)
  2. calculateSHA1(byte[] data)
  3. sha1(byte[] bytesOfMessage)
  4. getCertificateSHA1(X509Certificate certificate)
  5. hmacSha1(byte[] value, byte[] key)
  6. encryptByUsingSha1(String passwd)
  7. generateDigest(byte[] inputBytes)