/** 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); }
public ASN1ObjectIdentifier getContentType() { return contentInfo.getContentType(); }
public static ContentInfo getInstance( ASN1TaggedObject obj, boolean explicit) { return getInstance(ASN1Sequence.getInstance(obj, explicit)); }
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; }
private void initialize(ContentInfo contentInfo) { this.contentInfo = contentInfo; if (CMSObjectIdentifiers.timestampedData.equals(contentInfo.getContentType())) { this.timeStampedData = TimeStampedData.getInstance(contentInfo.getContent()); } else { throw new IllegalArgumentException("Malformed content - type must be " + CMSObjectIdentifiers.timestampedData.getId()); } util = new TimeStampDataUtil(this.timeStampedData); }
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(); }
public CMSEncryptedData(ContentInfo contentInfo) { this.contentInfo = contentInfo; this.encryptedData = EncryptedData.getInstance(contentInfo.getContent()); }
/** * return the ASN.1 encoded representation of this object. */ public byte[] getEncoded() throws IOException { return contentInfo.getEncoded(); }
public ASN1Primitive toASN1Primitive() { if (genTime != null) { return genTime; } else { return timeStampToken.toASN1Primitive(); } }
/** * 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; }
private void initialize(ContentInfo contentInfo) { this.contentInfo = contentInfo; if (CMSObjectIdentifiers.timestampedData.equals(contentInfo.getContentType())) { this.timeStampedData = TimeStampedData.getInstance(contentInfo.getContent()); } else { throw new IllegalArgumentException("Malformed content - type must be " + CMSObjectIdentifiers.timestampedData.getId()); } util = new TimeStampDataUtil(this.timeStampedData); }
EnvelopedData enveloped = new EnvelopedData(null, set, encryptedInfo, (ASN1Set) null); ContentInfo contentInfo = new ContentInfo(PKCSObjectIdentifiers.envelopedData, enveloped); return contentInfo.toASN1Primitive();
public CMSEncryptedData(ContentInfo contentInfo) { this.contentInfo = contentInfo; this.encryptedData = EncryptedData.getInstance(contentInfo.getContent()); }
/** * return the ASN.1 encoded representation of this object. */ public byte[] getEncoded() throws IOException { return contentInfo.getEncoded(); }
return new TimeStampResponse(new DLSequence(new ASN1Encodable[] { pkiStatusInfo.toASN1Primitive(), tstTokenContentInfo.toASN1Primitive() }));
/** 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); }
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)); } }
/** * Return the digested content * * @return the digested content * @throws CMSException if there is an exception un-compressing the data. */ public CMSProcessable getDigestedContent() throws CMSException { ContentInfo content = digestedData.getEncapContentInfo(); try { return new CMSProcessableByteArray(content.getContentType(), ((ASN1OctetString)content.getContent()).getOctets()); } catch (Exception e) { throw new CMSException("exception reading digested stream.", e); } }
/** Crea un object CMS DigestedData a partir de una Secuencia ASN.1. * @param seq Secuencia origen */ public DigestedData(final ASN1Sequence seq) { final Enumeration<?> e = seq.getObjects(); this.version = (ASN1Integer) e.nextElement(); this.digestAlgorithm = AlgorithmIdentifier.getInstance(e.nextElement()); this.contentInfo = ContentInfo.getInstance(e.nextElement()); this.digest = (ASN1OctetString) e.nextElement(); }
public ASN1ObjectIdentifier getContentType() { return contentInfo.getContentType(); }