Search in sources :

Example 16 with X509CRLEntry

use of java.security.cert.X509CRLEntry in project jdk8u_jdk by JetBrains.

the class OrderAndDup method main.

public static void main(String[] args) throws Exception {
    // Generate 20 serial numbers with dup and a special order
    int count = 20;
    BigInteger[] serials = new BigInteger[count];
    for (int i = 0; i < count; i++) {
        serials[i] = BigInteger.valueOf(i * 7 % 10);
    }
    // Generates a CRL
    X509CRLEntry[] badCerts = new X509CRLEntry[count];
    for (int i = 0; i < count; i++) {
        badCerts[i] = new X509CRLEntryImpl(serials[i], new Date(System.currentTimeMillis() + i * 1000));
    }
    X500Name owner = new X500Name("CN=CA");
    X509CRLImpl crl = new X509CRLImpl(owner, new Date(), new Date(), badCerts);
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    crl.sign(kpg.genKeyPair().getPrivate(), "SHA1withRSA");
    byte[] data = crl.getEncodedInternal();
    // Check the encoding
    checkData(crl, data, serials);
    // Load a CRL from raw data
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509CRLImpl crl2 = (X509CRLImpl) cf.generateCRL(new ByteArrayInputStream(data));
    // Check the encoding again
    data = crl2.getEncodedInternal();
    checkData(crl2, data, serials);
}
Also used : KeyPairGenerator(java.security.KeyPairGenerator) CertificateFactory(java.security.cert.CertificateFactory) Date(java.util.Date) X509CRLEntry(java.security.cert.X509CRLEntry) ByteArrayInputStream(java.io.ByteArrayInputStream) BigInteger(java.math.BigInteger)

Aggregations

X509CRLEntry (java.security.cert.X509CRLEntry)16 IOException (java.io.IOException)6 CRLException (java.security.cert.CRLException)6 X509Certificate (java.security.cert.X509Certificate)5 X509CRL (java.security.cert.X509CRL)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 NoSuchProviderException (java.security.NoSuchProviderException)3 Enumeration (java.util.Enumeration)3 TBSCertList (org.bouncycastle.asn1.x509.TBSCertList)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BigInteger (java.math.BigInteger)2 GeneralSecurityException (java.security.GeneralSecurityException)2 InvalidKeyException (java.security.InvalidKeyException)2 PrivateKey (java.security.PrivateKey)2 SignatureException (java.security.SignatureException)2 CertStoreException (java.security.cert.CertStoreException)2 Certificate (java.security.cert.Certificate)2 CertificateException (java.security.cert.CertificateException)2 CertificateFactory (java.security.cert.CertificateFactory)2 Date (java.util.Date)2