Android Utililty Methods SHA1 Hash Create

List of utility methods to do SHA1 Hash Create

Description

The list of methods to do SHA1 Hash Create are organized into topic(s).

Method

byte[]calculateSHA1(byte[] data)
calculate SHA
try {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    return md.digest(data);
} catch (NoSuchAlgorithmException e) {
    e.printStackTrace();
return null;
Stringsha1(byte[] bytesOfMessage)
sha
if (bytesOfMessage.length == 0) {
    return null;
} else {
    try {
        MessageDigest sha1 = MessageDigest.getInstance("SHA1");
        byte[] hash = sha1.digest(bytesOfMessage);
        StringBuilder hexDigest = new StringBuilder();
        for (int i = 0; i < hash.length; i++) {
...
StringgetCertificateSHA1(X509Certificate certificate)
get Certificate SHA
MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
byte[] der = certificate.getEncoded();
messageDigest.update(der);
byte[] digest = messageDigest.digest();
return hexify(digest);
byte[]hmacSha1(byte[] value, byte[] key)
hmac Sha
try {
    SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
    Mac mac = Mac.getInstance("HmacSHA1");
    mac.init(signingKey);
    return mac.doFinal(value);
} catch (Exception e) {
    throw new RuntimeException(e);
StringcomputeSHAHash(String password)
compute SHA Hash
MessageDigest mdSha1 = null;
String SHAHash;
mdSha1 = MessageDigest.getInstance("SHA-1");
mdSha1.update(password.getBytes("ASCII"));
byte[] data = mdSha1.digest();
SHAHash = convertToHex(data);
return SHAHash;
StringencryptByUsingSha1(String passwd)
encrypt By Using Sha
try {
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    String clearPassword = passwd;
    md.update(clearPassword.getBytes());
    byte[] digestedPassword = md.digest();
    return new String(digestedPassword);
} catch (java.security.NoSuchAlgorithmException e) {
    System.out.println("Rats, SHA-1 doesn't exist");
...
byte[]generateDigest(byte[] inputBytes)
Generate a (SHA1) digest of the input bytes.
try {
    if (digest == null)
        digest = MessageDigest.getInstance("SHA-1");
    return digest.digest(inputBytes);
} catch (Exception e) {
    throw new Exception("[SecUtil] Error in generating digest");