Example usage for org.bouncycastle.asn1.x509 SubjectKeyIdentifier getEncoded

List of usage examples for org.bouncycastle.asn1.x509 SubjectKeyIdentifier getEncoded

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 SubjectKeyIdentifier getEncoded.

Prototype

public byte[] getEncoded(String encoding) throws IOException 

Source Link

Document

Return either the default for "BER" or a DER encoding if "DER" is specified.

Usage

From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DSubjectKeyIdentifier.java

License:Open Source License

private void okPressed() {
    byte[] keyIdentifier = jkiKeyIdentifier.getKeyIdentifier();

    if (keyIdentifier == null) {
        JOptionPane.showMessageDialog(this, res.getString("DSubjectKeyIdentifier.ValueReq.message"), getTitle(),
                JOptionPane.WARNING_MESSAGE);
        return;//from   ww  w.j  av  a2 s  . c  om
    }

    SubjectKeyIdentifier subjectKeyIdentifier = new SubjectKeyIdentifier(keyIdentifier);

    try {
        value = subjectKeyIdentifier.getEncoded(ASN1Encoding.DER);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }

    closeDialog();
}

From source file:se.tillvaxtverket.tsltrust.webservice.daemon.ca.RootCAFactory.java

License:Open Source License

private static AaaCertificate createRootCertificate(X500Name subjectIssuer, PublicKey publicKey,
        PrivateKey privateKey, String algorithm, List<Extension> extensions)
        throws OperatorCreationException, IOException, CertificateException {

    CertRequestModel reqMod = new CertRequestModel();
    reqMod.setSubjectDN(subjectIssuer);/*from   ww  w.  ja v  a2 s  .com*/
    reqMod.setIssuerDN(subjectIssuer);
    reqMod.setSerialNumber(BigInteger.ONE);
    reqMod.setPublicKey(publicKey);

    //Add Signer
    ContentSigner rooSigner = new JcaContentSignerBuilder(algorithm).build(privateKey);
    reqMod.setSigner(rooSigner);

    // ensure that EE certs are in the validity period of CA certs
    GregorianCalendar notBefore = new GregorianCalendar();
    GregorianCalendar notAfter = new GregorianCalendar();
    notBefore.add(Calendar.YEAR, -2);
    notAfter.add(Calendar.YEAR, 5);
    reqMod.setNotBefore(notBefore.getTime());
    reqMod.setNotAfter(notAfter.getTime());

    X509ExtensionUtils extUtil = CertUtils.getX509ExtensionUtils();
    SubjectKeyIdentifier ski = extUtil.createSubjectKeyIdentifier(CertUtils.getPublicKeyInfo(publicKey));
    extensions.add(new Extension(Extension.subjectKeyIdentifier, false, ski.getEncoded("DER")));

    reqMod.setExtensionList(extensions);

    AaaCertificate cert = new AaaCertificate(reqMod);
    return cert;
}