public static ContentInfo getInstance( Object obj) { if (obj instanceof ContentInfo) { return (ContentInfo)obj; } else if (obj != null) { return new ContentInfo(ASN1Sequence.getInstance(obj)); } return null; }
/** * Return an ContentInfo object from the given object. * <p> * Accepted inputs: * <ul> * <li> null → null * <li> {@link ContentInfo} object * <li> {@link org.spongycastle.asn1.ASN1Sequence#getInstance(java.lang.Object) ASN1Sequence} input formats with ContentInfo structure inside * </ul> * * @param obj the object we want converted. * @exception IllegalArgumentException if the object cannot be converted. */ public static ContentInfo getInstance( Object obj) { if (obj instanceof ContentInfo) { return (ContentInfo)obj; } else if (obj != null) { return new ContentInfo(ASN1Sequence.getInstance(obj)); } return null; }
protected DVCSRequest createDVCRequest(Data data) throws DVCSException { if (!extGenerator.isEmpty()) { requestInformationBuilder.setExtensions(extGenerator.generate()); } org.spongycastle.asn1.dvcs.DVCSRequest request = new org.spongycastle.asn1.dvcs.DVCSRequest(requestInformationBuilder.build(), data); return new DVCSRequest(new ContentInfo(DVCSObjectIdentifiers.id_ct_DVCSRequestData, request)); } }
protected DVCSRequest createDVCRequest(Data data) throws DVCSException { if (!extGenerator.isEmpty()) { requestInformationBuilder.setExtensions(extGenerator.generate()); } org.spongycastle.asn1.dvcs.DVCSRequest request = new org.spongycastle.asn1.dvcs.DVCSRequest(requestInformationBuilder.build(), data); return new DVCSRequest(new ContentInfo(DVCSObjectIdentifiers.id_ct_DVCSRequestData, request)); } }
/** Méodo que genera una estructura CMS de tipo Data. * @param content * Datos que se desean envolver. * @return El envoltorio de tipo data. * @throws IOException En caso de error en la lectura o tratamiento de datos */ static byte[] genData(final byte[] content) throws IOException { return new ContentInfo(PKCSObjectIdentifiers.data, new DEROctetString(content)).getEncoded(ASN1Encoding.DER); }
/** Obtiene un tipo CompressedData. * @param data * Datos a comprimir * @return Tipo CompressedData. * @throws IOException En caso de error en la lectura o tratamiento de datos */ static byte[] genCompressedData(final byte[] data) throws IOException { // Algoritmo de compresion final AlgorithmIdentifier comAlgId = new AlgorithmIdentifier(new ASN1ObjectIdentifier(ZLIB)); // Se comprimen los datos final byte[] compressed = BinaryUtils.compress(data); final ASN1OctetString comOcts = new BEROctetString(compressed); // Contenido comprimido final ContentInfo comContent = new ContentInfo(CMSObjectIdentifiers.data, comOcts); return new ContentInfo(CMSObjectIdentifiers.compressedData, new CompressedData(comAlgId, comContent)).getEncoded(ASN1Encoding.DER); }
final ContentInfo encInfo = new ContentInfo(contentTypeOID, null); return new ContentInfo(PKCSObjectIdentifiers.digestedData, new DigestedData(digAlgId, encInfo, digest)).getEncoded(ASN1Encoding.DER);
ContentInfo comContent = new ContentInfo( content.getContentType(), comOcts); ContentInfo contentInfo = new ContentInfo( CMSObjectIdentifiers.compressedData, new CompressedData(comAlgId, comContent));
ContentInfo comContent = new ContentInfo( content.getContentType(), comOcts); ContentInfo contentInfo = new ContentInfo( CMSObjectIdentifiers.compressedData, new CompressedData(comAlgId, comContent));
/** * Return the enveloped data structure contained in this control. * * @return a CMSEnvelopedData object. */ public CMSEnvelopedData getEnvelopedData() throws CRMFException { try { EncryptedKey encKey = EncryptedKey.getInstance(pkiArchiveOptions.getValue()); EnvelopedData data = EnvelopedData.getInstance(encKey.getValue()); return new CMSEnvelopedData(new ContentInfo(CMSObjectIdentifiers.envelopedData, data)); } catch (CMSException e) { throw new CRMFException("CMS parsing error: " + e.getMessage(), e.getCause()); } catch (Exception e) { throw new CRMFException("CRMF parsing error: " + e.getMessage(), e); } } }
/** * Return the enveloped data structure contained in this control. * * @return a CMSEnvelopedData object. */ public CMSEnvelopedData getEnvelopedData() throws CRMFException { try { EncryptedKey encKey = EncryptedKey.getInstance(pkiArchiveOptions.getValue()); EnvelopedData data = EnvelopedData.getInstance(encKey.getValue()); return new CMSEnvelopedData(new ContentInfo(CMSObjectIdentifiers.envelopedData, data)); } catch (CMSException e) { throw new CRMFException("CMS parsing error: " + e.getMessage(), e.getCause()); } catch (Exception e) { throw new CRMFException("CRMF parsing error: " + e.getMessage(), e); } } }
private ASN1Primitive createDERForRecipient(byte[] in, X509Certificate cert) throws IOException, GeneralSecurityException { String s = "1.2.840.113549.3.2"; AlgorithmParameterGenerator algorithmparametergenerator = AlgorithmParameterGenerator.getInstance(s); AlgorithmParameters algorithmparameters = algorithmparametergenerator.generateParameters(); ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(algorithmparameters.getEncoded("ASN.1")); ASN1InputStream asn1inputstream = new ASN1InputStream(bytearrayinputstream); ASN1Primitive derobject = asn1inputstream.readObject(); KeyGenerator keygenerator = KeyGenerator.getInstance(s); keygenerator.init(128); SecretKey secretkey = keygenerator.generateKey(); Cipher cipher = Cipher.getInstance(s); cipher.init(1, secretkey, algorithmparameters); byte[] abyte1 = cipher.doFinal(in); DEROctetString deroctetstring = new DEROctetString(abyte1); KeyTransRecipientInfo keytransrecipientinfo = computeRecipientInfo(cert, secretkey.getEncoded()); DERSet derset = new DERSet(new RecipientInfo(keytransrecipientinfo)); AlgorithmIdentifier algorithmidentifier = new AlgorithmIdentifier(new ASN1ObjectIdentifier(s), derobject); EncryptedContentInfo encryptedcontentinfo = new EncryptedContentInfo(PKCSObjectIdentifiers.data, algorithmidentifier, deroctetstring); ASN1Set set = null; EnvelopedData env = new EnvelopedData(null, derset, encryptedcontentinfo, set); ContentInfo contentinfo = new ContentInfo(PKCSObjectIdentifiers.envelopedData, env); return contentinfo.toASN1Primitive(); }
return new ContentInfo(PKCSObjectIdentifiers.encryptedData, new EncryptedData(encInfo, unprotectedAttrs)).getEncoded(ASN1Encoding.DER);
EnvelopedData enveloped = new EnvelopedData(null, set, encryptedInfo, (ASN1Set) null); ContentInfo contentInfo = new ContentInfo(PKCSObjectIdentifiers.envelopedData, enveloped); return contentInfo.toASN1Primitive();
return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, new TimeStampedData(asn1DataUri, metaData, encContent, new Evidence(new TimeStampTokenEvidence(stamp)))));
return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, new TimeStampedData(asn1DataUri, metaData, encContent, new Evidence(new TimeStampTokenEvidence(stamp)))));
ContentInfo contentInfo = new ContentInfo( CMSObjectIdentifiers.encryptedData, new EncryptedData(eci, unprotectedAttrSet));
ContentInfo contentInfo = new ContentInfo( CMSObjectIdentifiers.encryptedData, new EncryptedData(eci, unprotectedAttrSet));
/** * Return a new timeStampedData object with the additional token attached. * * @throws CMSException */ public CMSTimeStampedData addTimeStamp(TimeStampToken token) throws CMSException { TimeStampAndCRL[] timeStamps = util.getTimeStamps(); TimeStampAndCRL[] newTimeStamps = new TimeStampAndCRL[timeStamps.length + 1]; System.arraycopy(timeStamps, 0, newTimeStamps, 0, timeStamps.length); newTimeStamps[timeStamps.length] = new TimeStampAndCRL(token.toCMSSignedData().toASN1Structure()); return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, new TimeStampedData(timeStampedData.getDataUri(), timeStampedData.getMetaData(), timeStampedData.getContent(), new Evidence(new TimeStampTokenEvidence(newTimeStamps))))); }
/** * Return a new timeStampedData object with the additional token attached. * * @throws CMSException */ public CMSTimeStampedData addTimeStamp(TimeStampToken token) throws CMSException { TimeStampAndCRL[] timeStamps = util.getTimeStamps(); TimeStampAndCRL[] newTimeStamps = new TimeStampAndCRL[timeStamps.length + 1]; System.arraycopy(timeStamps, 0, newTimeStamps, 0, timeStamps.length); newTimeStamps[timeStamps.length] = new TimeStampAndCRL(token.toCMSSignedData().toASN1Structure()); return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, new TimeStampedData(timeStampedData.getDataUri(), timeStampedData.getMetaData(), timeStampedData.getContent(), new Evidence(new TimeStampTokenEvidence(newTimeStamps))))); }