Android SHA1 Hash Create getCertificateSHA1(X509Certificate certificate)

Here you can find the source of getCertificateSHA1(X509Certificate certificate)

Description

get Certificate SHA

License

Apache License

Declaration

private static String getCertificateSHA1(X509Certificate certificate)
            throws NoSuchAlgorithmException, CertificateEncodingException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateEncodingException;

import java.security.cert.X509Certificate;

public class Main {
    private static String getCertificateSHA1(X509Certificate certificate)
            throws NoSuchAlgorithmException, CertificateEncodingException {
        MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
        byte[] der = certificate.getEncoded();
        messageDigest.update(der);/*from   w  ww  .j a  v  a2 s .c o m*/
        byte[] digest = messageDigest.digest();
        return hexify(digest);
    }

    private static String hexify(byte bytes[]) {
        char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
                '9', 'a', 'b', 'c', 'd', 'e', 'f' };

        StringBuffer buf = new StringBuffer(bytes.length * 2);
        for (int i = 0; i < bytes.length; ++i) {
            buf.append(hexDigits[(bytes[i] & 0xf0) >> 4]);
            buf.append(hexDigits[bytes[i] & 0x0f]);
        }
        return buf.toString();
    }
}

Related

  1. SHA1(String text)
  2. shaByte(String in)
  3. shaByte(byte[] in)
  4. calculateSHA1(byte[] data)
  5. sha1(byte[] bytesOfMessage)
  6. hmacSha1(byte[] value, byte[] key)
  7. computeSHAHash(String password)
  8. encryptByUsingSha1(String passwd)
  9. generateDigest(byte[] inputBytes)