Android SHA1 Hash Create sha1(String s)

Here you can find the source of sha1(String s)

Description

sha

Declaration

public static String sha1(String s) 

Method Source Code

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

public class Main {
    public static String sha1(String s) {
        return hash(s, "SHA1");
    }/* w  w  w .  ja  va2s  .c o  m*/

    private static String hash(String s, String algorithm) {
        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) {
            // No way...
        }
        return result;
    }
}

Related

  1. sha1(File input)
  2. sha1(String input)
  3. sha1(String ori)
  4. sha1(String ori)
  5. sha1(String s)
  6. computeHashSHA1(final String text)
  7. computeSHAHash(String password)
  8. getSHA1CertFingerprint(Context ctx)
  9. SHA1(String text)