Example usage for org.bouncycastle.asn1 ASN1UTCTime getDate

List of usage examples for org.bouncycastle.asn1 ASN1UTCTime getDate

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 ASN1UTCTime getDate.

Prototype

public Date getDate() throws ParseException 

Source Link

Document

Return the time as a date based on whatever a 2 digit year will return.

Usage

From source file:bluecrystal.bcdeps.helper.DerEncoder.java

License:Open Source License

public static void extractSignPolicyRefFromSignedAttrib(DERTaggedObject signedAttribsDTO,
        SignCompare signCompare) throws Exception {
    //      String SignCompare = null;
    ASN1Primitive dtoObj = signedAttribsDTO.getObject();
    if (dtoObj instanceof DLSequence) {
        DLSequence topSeq = (DLSequence) dtoObj;
        List<String> signedAttribOid = new ArrayList<String>();
        signCompare.setSignedAttribs(signedAttribOid);
        for (int i = 0; i < topSeq.size(); i++) {
            // treat each SIGNED ATTRIBUTE
            ASN1Encodable objL1 = topSeq.getObjectAt(i);
            if (objL1 instanceof DERSequence) {
                DERSequence seqL1 = (DERSequence) objL1;
                ASN1Encodable objL2 = seqL1.getObjectAt(0);
                if (objL2 instanceof ASN1ObjectIdentifier) {
                    ASN1ObjectIdentifier saOid = (ASN1ObjectIdentifier) objL2;
                    String saOIdStr = saOid.toString();
                    // System.out.println(saOIdStr);
                    signedAttribOid.add(saOIdStr);

                    if (saOIdStr.compareTo(DerEncoder.ID_SIG_POLICY) == 0) {
                        ASN1Encodable objL21 = seqL1.getObjectAt(1);
                        if (objL21 instanceof DERSet) {
                            DERSet objL21Set = (DERSet) objL21;
                            ASN1Encodable objL3 = objL21Set.getObjectAt(0);
                            if (objL3 instanceof DERSequence) {
                                DERSequence objL3Seq = (DERSequence) objL3;
                                ASN1Encodable objL4 = objL3Seq.getObjectAt(0);
                                if (objL4 instanceof ASN1ObjectIdentifier) {
                                    ASN1ObjectIdentifier objL4Oid = (ASN1ObjectIdentifier) objL4;
                                    signCompare.setPsOid(objL4Oid.toString());
                                }//from  w w w .j a v a2  s. c o  m
                                ASN1Encodable objL42 = getAt(objL3Seq, 2);
                                if (objL42 instanceof DERSequence) {
                                    DERSequence objL42DerSeq = (DERSequence) objL42;
                                    ASN1Encodable objL420 = getAt(objL42DerSeq, 0);
                                    if (objL420 instanceof DERSequence) {
                                        DERSequence objL420DerSeq = (DERSequence) objL420;
                                        ASN1Encodable psUrl = getAt(objL420DerSeq, 1);
                                        if (psUrl instanceof DERIA5String) {
                                            DERIA5String psUrlIA5 = (DERIA5String) psUrl;
                                            signCompare.setPsUrl(psUrlIA5.getString());
                                        }
                                    }
                                }

                            }
                        }
                    } else if (saOIdStr.compareTo(DerEncoder.ID_SIGNING_TIME) == 0) {
                        ASN1Encodable objL2SetTime = seqL1.getObjectAt(1);
                        if (objL2SetTime instanceof DERSet) {
                            DERSet objL2SetTimeDer = (DERSet) objL2SetTime;
                            ASN1Encodable objL2SignTime = objL2SetTimeDer.getObjectAt(0);
                            if (objL2SignTime instanceof ASN1UTCTime) {
                                ASN1UTCTime objL2SignTimeUTC = (ASN1UTCTime) objL2SignTime;
                                signCompare.setSigningTime(objL2SignTimeUTC.getDate());
                            }

                        }

                    }
                }
            }
        }
    }

}

From source file:eu.europa.ec.markt.dss.DSSASN1Utils.java

License:Open Source License

public static Date toDate(final ASN1UTCTime attrValue) throws DSSException {

    try {//from  ww w .  j a  va  2s. co  m
        return attrValue.getDate();
    } catch (ParseException e) {
        throw new DSSException(e);
    }
}

From source file:eu.europa.esig.dss.DSSASN1Utils.java

License:Open Source License

public static Date toDate(final ASN1UTCTime asn1Date) throws DSSException {
    try {// w ww.  j  a  v a 2s. com
        return asn1Date.getDate();
    } catch (ParseException e) {
        throw new DSSException(e);
    }
}

From source file:net.sf.keystore_explorer.utilities.asn1.Asn1Dump.java

License:Open Source License

private String dumpUTCTime(ASN1UTCTime asn1Time) {
    StringBuilder sb = new StringBuilder();

    sb.append(indentSequence.toString(indentLevel));
    sb.append("UTC TIME=");

    // UTCTime, note does not support ms precision hence the different date format
    Date date;/*from  w w  w  . jav  a  2  s .c  o m*/
    try {
        date = asn1Time.getDate();
    } catch (ParseException e) {
        throw new RuntimeException("Cannot parse utc time");
    }
    String formattedDate = new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss z").format(date);

    sb.append(formattedDate);
    sb.append(" (");
    sb.append(asn1Time.getTime());
    sb.append(")");
    sb.append(NEWLINE);

    return sb.toString();
}

From source file:org.votingsystem.signature.smime.SMIMESignedValidator.java

License:Open Source License

public static Date getSigningTime(SignerInformation signerInformation) {
    AttributeTable signedAttr = signerInformation.getSignedAttributes();
    Attribute signingTime = signedAttr.get(CMSAttributes.signingTime);
    if (signingTime != null) {
        try {/*from w  ww  .j  a  v  a2s.  c  om*/
            Enumeration en = signingTime.getAttrValues().getObjects();
            while (en.hasMoreElements()) {
                Object obj = en.nextElement();
                if (obj instanceof ASN1UTCTime) {
                    ASN1UTCTime asn1Time = (ASN1UTCTime) obj;
                    return asn1Time.getDate();
                } else if (obj instanceof DERUTCTime) {
                    DERUTCTime derTime = (DERUTCTime) obj;
                    return derTime.getDate();
                }
            }
        } catch (Exception ex) {
            log.log(Level.SEVERE, ex.getMessage(), ex);
        }
    }
    return null;
}

From source file:se.tillvaxtverket.ttsigvalws.ttwssigvalidation.pdf.PdfSignatureVerifier.java

License:Open Source License

private static Date getClaimedSigningTime(SignerInformation signer) {
    try {//  w  w  w . j  a  va2s. com
        AttributeTable signedAttributes = signer.getSignedAttributes();
        Attribute sigTimeAttr = signedAttributes.get(new ASN1ObjectIdentifier("1.2.840.113549.1.9.5"));
        ASN1Encodable[] attributeValues = sigTimeAttr.getAttributeValues();
        ASN1UTCTime utcTime = (ASN1UTCTime) attributeValues[0];
        return utcTime.getDate();
    } catch (Exception e) {
        return null;
    }
}