Java 8 Certificate - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Certificate class.

This code example shows how to use the following methods: getPublicKey, getNotAfter, getNotBefore, getSerialNumber, getSigAlgName
 
		X509Certificate certificate = loadCertificate(certificatePath);
		 
		X509V3CertificateGenerator certGenerator = new X509V3CertificateGenerator();
 
		certGenerator.setSerialNumber(certificate.getSerialNumber());
		certGenerator.setPublicKey(certificate.getPublicKey());
		certGenerator.setSubjectDN(certificate.getSubjectX500Principal());
		certGenerator.setIssuerDN(issuerCertificate.getSubjectX500Principal());
		certGenerator.setNotBefore(certificate.getNotBefore());
		certGenerator.setNotAfter(certificate.getNotAfter());
		certGenerator.setSignatureAlgorithm(certificate.getSigAlgName());
 
		X509Certificate signedCertificate = certGenerator.generate(issuerPrivateKey);
 
		File file = new File(outPutCertificatePath);
		if (!file.exists()) {
			FileUtils.touch(file);
		} 
		 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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");
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getEncoded, getType
        DataOutputStream    dOut)
        throws IOException 
    { 
        try 
        { 
            byte[]      cEnc = cert.getEncoded();
 
            dOut.writeUTF(cert.getType());
            dOut.writeInt(cEnc.length);
            dOut.write(cEnc);
        } 
        catch (CertificateEncodingException ex)
        { 
            throw new IOException(ex.toString());
        } 
    } 
 
    private Certificate decodeCertificate(
        DataInputStream   dIn)
        throws IOException 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getEncoded, getIssuerDN, getIssuerX500Principal, getSerialNumber
             *  
             * XXX: not correct according to RFC 4514. 
             */ 
            // TODO: check if issuerName is different on getTBSCertificate 
            // issuerName = PrincipalUtil.getIssuerX509Principal(certificate).getName().replace(",", ", "); 
            issuerName = certificate.getIssuerDN().getName().replace(",", ", ");
        } else { 
            issuerName = certificate.getIssuerX500Principal().toString();
        } 
        issuerSerial.setX509IssuerName(issuerName);
        issuerSerial.setX509SerialNumber(certificate.getSerialNumber());
 
        byte[] encodedCertificate;
        try { 
            encodedCertificate = certificate.getEncoded();
        } catch (CertificateEncodingException e) {
            throw new RuntimeException("certificate encoding error: "
                    + e.getMessage(), e);
        } 
        DigestAlgAndValueType certDigest = certId.addNewCertDigest(); 
Full Snippet Info
6
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getType, getIssuerDN, getNotAfter, getNotBefore, getSubjectDN
	} 
 
	public void list(String alias, Certificate cert) {
		if (cert instanceof X509Certificate) {
			X509Certificate x509 = (X509Certificate) cert;
			System.out.println(" " + alias + " (" + x509.getType() + ")\n" +
					"  valid from " + x509.getNotBefore() + " to " + x509.getNotAfter() + "\n" +
					"  for        " + x509.getSubjectDN().getName() + "\n" +
					"  issued by  " + x509.getIssuerDN().getName());
		} else { 
			System.out.println(" " + alias + " (" + cert.getType() + ")");
		} 
	} 
 
	public void print(Certificate c) {
		System.out.println(c.getType() + " " + c);
	} 
 
	abstract void run(File keystore, Map args) throws Exception;
} 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 Certificate Questions & Answers:

See Code Examples for Java 8 Certificate Methods: