[prev in list] [next in list] [prev in thread] [next in thread]
List: bouncycastle-crypto-dev
Subject: [dev-crypto] Re: HOW TO SAVE ATTACHED CMSSIGNEDDATA TO DISK
From: Niels Stevens <steniels () gmail ! com>
Date: 2010-05-28 10:13:05
Message-ID: 7E239AD7-D9A8-4DC1-91FF-2F63CBDD2125 () gmail ! com
[Download RAW message or body]
I have done it like David has mentioned, I put the CMS into an SMIME.
Afterwards I use an ByteArrayOutputstream something like this :
CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
generator.addSigner(privateKey, (X509Certificate) userCert, \
CMSSignedDataGenerator.DIGEST_SHA1); generator.addCertificatesAndCRLs(store);
CMSProcessable content = new \
CMSProcessableByteArray(json.toString().getBytes("ASCII"));
CMSSignedData signedData = generator.generate(content, true, "BC");
//END SIGNED PKCS7
Session session = null;
MimeMessage msg = new MimeMessage(session);
msg.setDisposition("attachment; filename=smime.p7m");
String contentType = "application/x-pkcs7-mime; smime-type=signed-data; \
name=smime.p7m";
// If we have a file name, set the content type based on iterSigners.
msg.setContent(signedData.getEncoded(), contentType);
msg.saveChanges();
ByteArrayOutputStream out = new ByteArrayOutputStream();
msg.writeTo(out);
out.close();
smime = new String(out.toByteArray(), "ASCII");
Hopefully this is something useful for you.
Regards,
Niels
Op 28-mei-2010, om 01:03 heeft David Hook-2 [via Bouncy Castle] het volgende \
geschreven:
>
> Normally, you'd do this using S/MIME.
>
> Regards,
>
> David
>
> On Thu, 2010-05-27 at 14:19 -0300, Toyoaki Ejiri wrote:
>
> > Hello!
> >
> > My problem is that I need to save an attached CMSSignedData to a pkcs7
> > file.
> >
> > When I use the CMSSignedData.getEncoded() method to retrieve the byte
> > array and save it in the disk, bouncycastle gives me a byte array
> > without the attached document file (signedContent field of the
> > CMSSignedData) .
> >
> > Does anyone know what I have to do to get a byte[] that has the full
> > attached CMSSignedData?
> >
> > Best Regards,
> >
> > ---------------------------------------------------
> > Toyoaki Ejiri
> > ---------------------------------------------------
>
>
>
>
>
> View message @ http://bouncy-castle.1462172.n4.nabble.com/HOW-TO-SAVE-ATTACHED-CMSSIGNEDDATA-TO-DISK-tp2233493p2233927.html \
> To unsubscribe from Bouncy Castle, click here.
>
--
View this message in context: \
http://bouncy-castle.1462172.n4.nabble.com/HOW-TO-SAVE-ATTACHED-CMSSIGNEDDATA-TO-DISK-tp2233493p2234371.html
Sent from the Bouncy Castle - Dev mailing list archive at Nabble.com.
[Attachment #3 (text/html)]
I have done it like David has mentioned, I put the CMS into an SMIME.<div>Afterwards \
I use an ByteArrayOutputstream something like this \
:</div><div><br></div><div><div> CMSSignedDataGenerator generator = new \
CMSSignedDataGenerator();</div><div> \
generator.addSigner(privateKey, (X509Certificate) userCert, \
CMSSignedDataGenerator.DIGEST_SHA1);</div><div> \
generator.addCertificatesAndCRLs(store);</div><div> \
CMSProcessable content = new \
CMSProcessableByteArray(json.toString().getBytes("ASCII"));</div><div> \
CMSSignedData signedData = generator.generate(content, true, \
"BC");</div><div> //END SIGNED \
PKCS7</div><div><br></div><div> Session session = \
null;</div><div> MimeMessage msg = new \
MimeMessage(session);</div><div><br></div><div> \
msg.setDisposition("attachment; filename=smime.p7m");</div><div> \
String contentType = "application/x-pkcs7-mime; \
smime-type=signed-data; name=smime.p7m";</div><div> \
// If we have a file name, set the content type based on \
iterSigners.</div><div><br></div><div> \
msg.setContent(signedData.getEncoded(), \
contentType);</div><div><br></div><div> \
msg.saveChanges();</div><div> \
ByteArrayOutputStream out = new ByteArrayOutputStream();</div><div> \
msg.writeTo(out);</div><div> \
out.close();</div><div> smime = new \
String(out.toByteArray(), "ASCII");</div><div><br></div><div>Hopefully this is \
something useful for \
you.</div><div><br></div><div>Regards,</div><div><br></div><div>Niels</div><div><br></div><div><div>Op \
28-mei-2010, om 01:03 heeft David Hook-2 [via Bouncy Castle] het volgende \
geschreven:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<br>Normally, you'd do this using S/MIME.
<br><br>Regards,
<br><br>David
<br><br>On Thu, 2010-05-27 at 14:19 -0300, Toyoaki Ejiri wrote:
<div class="shrinkable-quote"><div class='shrinkable-quote'><br>> Hello!
<br>>
<br>> My problem is that I need to save an attached CMSSignedData to a pkcs7
<br>> file.
<br>>
<br>> When I use the CMSSignedData.getEncoded() method to retrieve the byte
<br>> array and save it in the disk, bouncycastle gives me a byte array
<br>> without the attached document file (signedContent field of the
<br>> CMSSignedData) .
<br>>
<br>> Does anyone know what I have to do to get a byte[] that has the full
<br>> attached CMSSignedData?
<br>>
<br>> Best Regards,
<br>>
<br>> ---------------------------------------------------
<br>> Toyoaki Ejiri
<br>> ---------------------------------------------------
</div></div><br><br>
<br><br>
<hr noshade="noshade" size="1" color="#cccccc">
<div style="color:#666666; font: 11px tahoma,geneva,helvetica,arial,sans-serif;">
View message @ <a href="http://bouncy-castle.1462172.n4.nabble.com/HOW-TO-SAVE-ATTACHED-CMSSIGNEDDATA-TO-DISK-tp2233493p2233927.html" \
target="_top" rel="nofollow" \
link="external">http://bouncy-castle.1462172.n4.nabble.com/HOW-TO-SAVE-ATTACHED-CMSSIGNEDDATA-TO-DISK-tp2233493p2233927.html</a>
<br>To unsubscribe from Bouncy Castle, <a target="_top" rel="nofollow" \
link="external">click here</a>. </div>
<br>
</blockquote></div><br></div>
<br><hr align="left" width="300">
View this message in context: <a \
href="http://bouncy-castle.1462172.n4.nabble.com/HOW-TO-SAVE-ATTACHED-CMSSIGNEDDATA-TO-DISK-tp2233493p2234371.html">Re: \
HOW TO SAVE ATTACHED CMSSIGNEDDATA TO DISK</a><br> Sent from the <a \
href="http://bouncy-castle.1462172.n4.nabble.com/Bouncy-Castle-Dev-f1462173.html">Bouncy \
Castle - Dev mailing list archive</a> at Nabble.com.<br>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic