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

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

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 PrivateKeyUsagePeriod 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.DPrivateKeyUsagePeriod.java

License:Open Source License

private void okPressed() {

    Date notBefore = jdtNotBefore.getDateTime();
    Date notAfter = jdtNotAfter.getDateTime();

    if ((notBefore == null) && (notAfter == null)) {
        JOptionPane.showMessageDialog(this, res.getString("DPrivateKeyUsagePeriod.ValueReq.message"),
                getTitle(), JOptionPane.WARNING_MESSAGE);
        return;//from   w  w  w.  jav  a  2  s.c om
    }

    // BC forgot the value constructor for PrivateKeyUsagePeriod...
    ASN1EncodableVector v = new ASN1EncodableVector();
    if (notBefore != null) {
        DERGeneralizedTime notBeforeGenTime = new DERGeneralizedTime(notBefore);
        v.add(new DERTaggedObject(false, 0, notBeforeGenTime));
    }
    if (notAfter != null) {
        DERGeneralizedTime notAfterGenTime = new DERGeneralizedTime(notAfter);
        v.add(new DERTaggedObject(false, 1, notAfterGenTime));
    }

    PrivateKeyUsagePeriod privateKeyUsagePeriod = PrivateKeyUsagePeriod.getInstance(new DERSequence(v));

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

    closeDialog();
}