Java 类org.bouncycastle.asn1.x509.PrivateKeyUsagePeriod 实例源码

项目:portecle    文件:X509Ext.java   
/**
 * Get Private Key Usage Period (2.5.29.16) extension value as a string.
 * 
 * <pre>
 * PrivateKeyUsagePeriod ::= SEQUENCE {
 *       notBefore       [0]     GeneralizedTime OPTIONAL,
 *       notAfter        [1]     GeneralizedTime OPTIONAL }
 * </pre>
 * 
 * @param bValue The octet string value
 * @return Extension value as a string
 * @throws IOException If an I/O problem occurs
 * @throws ParseException If a date formatting problem occurs
 */
private String getPrivateKeyUsagePeriod(byte[] bValue)
    throws IOException, ParseException
{
    PrivateKeyUsagePeriod pkup = PrivateKeyUsagePeriod.getInstance(bValue);

    StringBuilder strBuff = new StringBuilder();
    ASN1GeneralizedTime dTime;

    if ((dTime = pkup.getNotBefore()) != null)
    {
        strBuff.append(
            MessageFormat.format(RB.getString("PrivateKeyUsagePeriodNotBefore"), formatGeneralizedTime(dTime)));
    }

    if ((dTime = pkup.getNotAfter()) != null)
    {
        if (strBuff.length() != 0)
        {
            strBuff.append("<br><br>");
        }
        strBuff.append(
            MessageFormat.format(RB.getString("PrivateKeyUsagePeriodNotAfter"), formatGeneralizedTime(dTime)));
    }

    return strBuff.toString();
}
项目:keystore-explorer    文件:X509Ext.java   
private String getPrivateKeyUsagePeriodStringValue(byte[] value) throws IOException {
    // @formatter:off

    /*
     * PrivateKeyUsagePeriod ::= ASN1Sequence { notBefore [0]
     * ASN1GeneralizedTime OPTIONAL, notAfter [1] ASN1GeneralizedTime OPTIONAL }
     */

    // @formatter:on

    StringBuilder sb = new StringBuilder();

    PrivateKeyUsagePeriod privateKeyUsagePeriod = PrivateKeyUsagePeriod.getInstance(value);

    ASN1GeneralizedTime notBefore = privateKeyUsagePeriod.getNotBefore();
    ASN1GeneralizedTime notAfter = privateKeyUsagePeriod.getNotAfter();

    if (notBefore != null) {
        sb.append(MessageFormat.format(res.getString("NotBeforePrivateKeyUsagePeriod"),
                getGeneralizedTimeString(notBefore)));
    } else {
        sb.append(MessageFormat.format(res.getString("NotBeforePrivateKeyUsagePeriod"),
                res.getString("NoValue")));
    }
    sb.append(NEWLINE);

    if (notAfter != null) {
        sb.append(MessageFormat.format(res.getString("NotAfterPrivateKeyUsagePeriod"),
                getGeneralizedTimeString(notAfter)));
    } else {
        sb.append(MessageFormat.format(res.getString("NotAfterPrivateKeyUsagePeriod"),
                res.getString("NoValue")));
    }
    sb.append(NEWLINE);

    return sb.toString();
}
项目:keystore-explorer    文件:DPrivateKeyUsagePeriod.java   
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;
        }

        // 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();
    }