Code example for X509Certificate

Methods: getPublicKey

0
        return tmp.getPath();
    } 
 
    private static String getFingerprint(X509Certificate cert) throws NoSuchAlgorithmException {
        MessageDigest dgst = MessageDigest.getInstance("SHA512");
        byte[] encoded = cert.getPublicKey().getEncoded();
        byte[] fingerprint = dgst.digest(encoded);
        return IntegralToString.bytesToHexString(fingerprint, false);
    } 
 
    @Override 
    public void setUp() throws Exception { 
        super.setUp(); 
        // build some valid chains 
        KeyStore.PrivateKeyEntry pke = TestKeyStore.getServer().getPrivateKey("RSA", "RSA");
        chain = (X509Certificate[]) pke.getCertificateChain();
        X509Certificate root = chain[2];
        X509Certificate server = chain[0];
 
        // build the short and long chains 
        shortChain = new ArrayList<X509Certificate>();
        shortChain.add(root);
        longChain = new ArrayList<X509Certificate>();
        longChain.add(server);
 
        // we'll use the root as the pin for the short entry and the server as the pin for the long 
        shortPin = getFingerprint(root);