Code example for X509Certificate

Methods: getPublicKey

        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);
    public void setUp() throws Exception { 
        // 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>();
        longChain = new ArrayList<X509Certificate>();
        // we'll use the root as the pin for the short entry and the server as the pin for the long 
        shortPin = getFingerprint(root);
Stop searching for code, let great code find you!  Add Codota to your java IDE