EnvelopedData enveloped = new EnvelopedData(null, set, encryptedInfo, (ASN1Set) null); ContentInfo contentInfo = new ContentInfo(PKCSObjectIdentifiers.envelopedData, enveloped); return contentInfo.toASN1Primitive();
public static ContentInfo getInstance( ASN1TaggedObject obj, boolean explicit) { return getInstance(ASN1Sequence.getInstance(obj, explicit)); }
/** * Parses the provided ASN1 object and extracts a degenerate SignedData * instance. * * @param signedData the ASN1 object to parse. * @return a new degenerate SignedData instance. * @throws IOException if any I/O error occurs. */ public SignedData parse(ASN1Encodable signedData) throws IOException { LOGGER.entering(getClass().getName(), "parse", signedData); try { ContentInfo ci = ContentInfo.getInstance(signedData); ASN1Sequence seq = (ASN1Sequence) ci.getContent(); final SignedData sd = new SignedData(seq); LOGGER.exiting(getClass().getName(), "parse", sd); return sd; } catch (Exception e) { LOGGER.throwing(getClass().getName(), "parse", e); throw new IOException(e); } } }
public byte[] getEncoded() throws IOException { final DERObjectIdentifier contentType = PKCSObjectIdentifiers.signedData; final ContentInfo contentInfo = new ContentInfo(contentType, signedData); return contentInfo.getEncoded(); }
/** * {@inheritDoc} */ @Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("messageData [\n"); builder.append("\tcontentType: " + contentInfo.getContentType() + "\n"); builder.append("\tcontent: " + contentInfo.getContent() + "\n"); builder.append("]"); return builder.toString(); } }
/** * Provides a new instance of MessageData by wrapping the provided object. * * @param content the object to wrap. * @return a new instance of MessageData. */ public static MessageData getInstance(DEREncodable content) { ContentInfo info = new ContentInfo(CMSObjectIdentifiers.data, content); return new MessageData(info); }
final SignedData signedData = SignedData.getInstance(contentInfo.getContent()); if (content == null || content.getContent() == null) { data.write(content.toASN1Primitive().getEncoded()); data.write(getOriginalDocumentBytes()); } else { ASN1OctetString octet = (ASN1OctetString) content.getContent(); ContentInfo info2 = new ContentInfo(PKCSObjectIdentifiers.data, octet); final byte[] contentInfoBytes = info2.getEncoded(); if (LOG.isTraceEnabled()) { LOG.trace("Content Info: {}", DSSUtils.toHex(contentInfoBytes));
private EnvelopedData getEnvelopedData(DEREncodable content) throws IOException { // According to PKCS #9, data consists of an octet string. final ASN1OctetString octetString = (ASN1OctetString) content; final byte[] octets = octetString.getOctets(); final ContentInfo contentInfo = ContentInfo.getInstance(ASN1Object.fromByteArray(octets)); final DERObjectIdentifier contentType = contentInfo.getContentType(); if (contentType.equals(CMSObjectIdentifiers.envelopedData) == false) { LOGGER.warning("Expected envelopedData ContentInfo, was " + contentType); } return new EnvelopedData((ASN1Sequence) contentInfo.getContent()); }
this.content = new ContentInfo((ASN1Sequence) ASN1Object.fromByteArray(envelope.getEncoded())); assert(signedData.getEncapContentInfo().getContentType().equals(CMSObjectIdentifiers.data)); } catch (GeneralSecurityException e) { RuntimeException rt = new RuntimeException(e);
/** * Returns a BER-encoded byte array representation of this instance. * * @return a BER-encoded byte array. * @throws IOException if any error occurs. */ public byte[] getEncoded() throws IOException { return contentInfo.getEncoded(); }
/** * Returns the object wrapped in this MessageData. * * @return the wrapped object. */ public ASN1Encodable getContent() { return (ASN1Encodable) contentInfo.getContent(); }
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("pkcsPkiEnvelope [\n"); sb.append("\tcontentType: " + info.getContentType() + "\n"); sb.append("\tmessageData: " + msgData.toString().replaceAll("\n", "\n\t") + "\n"); sb.append("]"); return sb.toString(); } }
private DERObject 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); DERObject 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 DERObjectIdentifier(s), derobject); EncryptedContentInfo encryptedcontentinfo = new EncryptedContentInfo(PKCSObjectIdentifiers.data, algorithmidentifier, deroctetstring); EnvelopedData env = new EnvelopedData(null, derset, encryptedcontentinfo, null); ContentInfo contentinfo = new ContentInfo(PKCSObjectIdentifiers.envelopedData, env); return contentinfo.getDERObject(); }
import com.j256.simplemagic.ContentInfo; import com.j256.simplemagic.ContentInfoUtil; import com.j256.simplemagic.ContentType; // ... public class SimpleMagicSmokeTest { private final static Logger log = LoggerFactory.getLogger(SimpleMagicSmokeTest.class); @Test public void smokeTestSimpleMagic() throws IOException { ContentInfoUtil util = new ContentInfoUtil(); InputStream possibleGzipInputStream = getGzipInputStream(); ContentInfo info = util.findMatch(possibleGzipInputStream); log.info( info.toString() ); assertEquals( ContentType.GZIP, info.getContentType() ); }
public ASN1Primitive toASN1Primitive() { if (genTime != null) { return genTime; } else { return timeStampToken.toASN1Primitive(); } }
private ContentInfo getContentInfo() { DERObjectIdentifier contentType = CMSObjectIdentifiers.data; DEREncodable content = getContent(); return new ContentInfo(contentType, content); }
private void validate(final CMSSignedData pkiMessage) { SignedData sd = SignedData.getInstance(pkiMessage.toASN1Structure() .getContent()); LOGGER.debug("pkiMessage version: {}", sd.getVersion()); LOGGER.debug("pkiMessage contentInfo contentType: {}", sd .getEncapContentInfo().getContentType()); }
public byte[] getEncoded() throws IOException { return info.getEncoded(); }
@Override public byte[] getContentTimestampData(final TimestampToken timestampToken) { final ContentInfo contentInfo = cmsSignedData.toASN1Structure(); final SignedData signedData = SignedData.getInstance(contentInfo.getContent()); ContentInfo content = signedData.getEncapContentInfo(); if (content == null || content.getContent() == null) { // Detached signatures have either no encapContentInfo in signedData, or it exists but has no eContent final byte[] originalDocumentBytes = getOriginalDocumentBytes(); if (originalDocumentBytes != null) { return originalDocumentBytes; } else { LOG.error("No original data provided for content timestamp!"); return DSSUtils.EMPTY_BYTE_ARRAY; } } //else { ASN1OctetString octet = (ASN1OctetString) content.getContent(); return octet.getOctets(); // ContentInfo info2 = new ContentInfo(PKCSObjectIdentifiers.data, octet); // byte[] contentInfoBytes = null; // try { // contentInfoBytes = info2.getEncoded(); // } catch (IOException e) { // e.printStackTrace(); // } // if (LOG.isTraceEnabled()) { // LOG.trace("Content Info: {}", DSSUtils.toHex(contentInfoBytes)); // } // return contentInfoBytes; // return DSSUtils.EMPTY_BYTE_ARRAY; }
public SignedData( ASN1Set digestAlgorithms, ContentInfo contentInfo, ASN1Set certificates, ASN1Set crls, ASN1Set signerInfos) { this.version = calculateVersion(contentInfo.getContentType(), certificates, crls, signerInfos); this.digestAlgorithms = digestAlgorithms; this.contentInfo = contentInfo; this.certificates = certificates; this.crls = crls; this.signerInfos = signerInfos; this.crlsBer = crls instanceof BERSet; this.certsBer = certificates instanceof BERSet; }