Code example for X509Certificate

Methods: getPublicKey

0
    } 
 
    public static String getChromeFingerprint(X509Certificate cert)
            throws NoSuchAlgorithmException { 
        MessageDigest dgst = MessageDigest.getInstance("SHA1");
        byte[] encoded = cert.getPublicKey().getEncoded();
        byte[] fingerprint = dgst.digest(encoded);
 
        return "sha1/" + Base64.encodeToString(fingerprint, Base64.DEFAULT);
    } 
 
    public X509Certificate getTrustAnchor(X509Certificate[] chain)
            throws CertificateException { 
        try { 
            CertPath certPath = certificateFactory.generateCertPath(Arrays
                    .asList(chain));
            PKIXCertPathValidatorResult result = (PKIXCertPathValidatorResult) certPathValidator
                    .validate(certPath, pkixParams);
 
            if (result == null) {
                return null;