Certificate getPublicKey - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Certificate getPublicKey method.

This code example shows how to use the following methods:getPublicKey, getSigAlgName, getSignature, getTBSCertificate
    private void doTest( 
        String      certName)
        throws Exception 
    { 
        X509Certificate  cert = loadCert(certName);
        byte[]           tbs = cert.getTBSCertificate();
        Signature        sig = Signature.getInstance(cert.getSigAlgName(), "BC");
         
        sig.initVerify(cert.getPublicKey());
         
        sig.update(tbs);
         
        assertFalse(sig.verify(cert.getSignature()));
    } 
 
    private X509Certificate loadCert(
        String certName)
        throws Exception 
    { 
        CertificateFactory rd = CertificateFactory.getInstance("X.509", "BC");
7
CodeRank
This code example shows how to use the following methods:getPublicKey
        X509AttributeCertificate    aCert = new X509V2AttributeCertificate(attrCert);
        CertificateFactory          fact = CertificateFactory.getInstance("X.509","BC");
         
        X509Certificate             sCert = (X509Certificate)fact.generateCertificate(new ByteArrayInputStream(signCert));
         
        aCert.verify(sCert.getPublicKey(), "BC");
         
        // 
        // search test 
        // 
         
        List      list = new ArrayList();
         
        list.add(sCert);
         
        CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(list);
        CertStore store = CertStore.getInstance("Collection", ccsp);
         
        Collection certs = store.getCertificates(aCert.getIssuer());
        if (certs.size() != 1 || !certs.contains(sCert))

6
CodeRank
This code example shows how to use the following methods:getPublicKey
    public X509Certificate findIssuer(final X509Certificate c) {
        // match on verified issuer of Certificate 
        CertSelector selector = new CertSelector() {
            @Override public boolean match(X509Certificate ca) {
                try { 
                    c.verify(ca.getPublicKey());
                    return true; 
                } catch (Exception e) {
                    return false; 
                } 
            } 
        }; 
        X500Principal issuer = c.getIssuerX500Principal();
        X509Certificate user = findCert(addedDir, issuer, selector, X509Certificate.class);
        if (user != null) {
            return user;
        } 
        X509Certificate system = findCert(systemDir, issuer, selector, X509Certificate.class);
        if (system != null && !isDeletedSystemCertificate(system)) {
            return system;
6
CodeRank
This code example shows how to use the following methods:getPublicKey, verify
This code example shows how to use the following methods:getPublicKey, getIssuerDN, getNotAfter, getNotBefore, getSerialNumber
    } 
 
    private static CertData fillCertData(X509Certificate cert, Format formatter) throws CertificateEncodingException {
 
        CertData certData = new CertData();
        certData.setSubjectDN(cert.getSubjectDN().getName());
        certData.setIssuerDN(cert.getIssuerDN().getName());
        certData.setSerialNumber(cert.getSerialNumber());
        certData.setVersion(cert.getVersion());
        certData.setNotAfter(formatter.format(cert.getNotAfter()));
        certData.setNotBefore(formatter.format(cert.getNotBefore()));
        certData.setPublicKey(Base64.encode(cert.getPublicKey().getEncoded()));
        return certData;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getPublicKey
        try 
        { 
            MessageDigest digest = OCSPUtil.createDigestInstance(hashAlg.getAlgorithm() .getId(),
                provider);
 
            X509Principal issuerName = PrincipalUtil.getSubjectX509Principal(issuerCert);
 
            digest.update(issuerName.getEncoded());
 
            ASN1OctetString issuerNameHash = new DEROctetString(digest.digest());
            PublicKey issuerKey = issuerCert.getPublicKey();
 
            ASN1InputStream aIn = new ASN1InputStream(issuerKey.getEncoded());
            SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(aIn.readObject());
 
            digest.update(info.getPublicKeyData().getBytes());
 
            ASN1OctetString issuerKeyHash = new DEROctetString(digest.digest());
 
            return new CertID(hashAlg, issuerNameHash, issuerKeyHash, serialNumber);
6
CodeRank
This code example shows how to use the following methods:getPublicKey
    } 
 
    private void verifySigner(SignerInformation signer, X509Certificate cert)
        throws Exception 
    { 
        if (cert.getPublicKey() instanceof DSAPublicKey)
        { 
            DSAPublicKey key = (DSAPublicKey)cert.getPublicKey();
 
            if (key.getParams() == null)
            { 
                assertEquals(true, signer.verify(getInheritedKey(key), BC));
            } 
            else 
            { 
                assertEquals(true, signer.verify(cert, BC));
            } 
        } 
        else 
        { 

6
CodeRank
This code example shows how to use the following methods:getPublicKey
     * @throws CertificateEncodingException  if the necessary data cannot be extracted from the certificate. 
     */ 
    public JceKeyAgreeRecipientInfoGenerator addRecipient(X509Certificate recipientCert)
        throws CertificateEncodingException 
    { 
        recipientIDs.add(new KeyAgreeRecipientIdentifier(CMSUtils.getIssuerAndSerialNumber(recipientCert)));
        recipientKeys.add(recipientCert.getPublicKey());
 
        return this;
    } 
 
    /** 
     * Add a recipient identified by the passed in subjectKeyID and the for the passed in public key. 
     * 
     * @param subjectKeyID identifier actual recipient will use to match the private key. 
     * @param publicKey the public key for encrypting the secret key. 
     * @return the current instance. 
     * @throws CertificateEncodingException 
     */ 
    public JceKeyAgreeRecipientInfoGenerator addRecipient(byte[] subjectKeyID, PublicKey publicKey)
6
CodeRank
This code example shows how to use the following methods:getPublicKey, checkValidity
        boolean addedCertificate = false;
        X509Certificate cert = (X509Certificate) keystore.getCertificate(keyName);
 
        if (cert != null) {
            try { 
                cert.checkValidity();
            } catch (CertificateExpiredException cee) {
                addedCertificate = false;
            } catch (CertificateNotYetValidException cnyve) {
                addedCertificate = false;
            } 
 
            sig.addKeyInfo(cert);
            sig.addKeyInfo(cert.getPublicKey());
            addedCertificate = true;
        } 
 
        return addedCertificate;
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getPublicKey
        this.publicKey = publicKey;
    } 
 
    public JceAsymmetricKeyWrapper(X509Certificate certificate)
    { 
        this(certificate.getPublicKey());
    } 
 
    /** 
     * Create a wrapper, overriding the algorithm type that is stored in the public key. 
     * 
     * @param algorithmIdentifier identifier for encryption algorithm to be used. 
     * @param publicKey the public key to be used. 
     */ 
    public JceAsymmetricKeyWrapper(AlgorithmIdentifier algorithmIdentifier, PublicKey publicKey)
    { 
        super(algorithmIdentifier);
 
        this.publicKey = publicKey;
    } 
5
CodeRank
getPublicKey Method Overview
Gets the public key from this certificate.
See Code Examples for other Java 8 Certificate Methods: