This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Security and the fly likes Want to add metadata (XML) into the conent of  CMSSignedData!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Want to add metadata (XML) into the conent of  CMSSignedData!!" Watch "Want to add metadata (XML) into the conent of  CMSSignedData!!" New topic
Author

Want to add metadata (XML) into the conent of CMSSignedData!!

amulya mishra
Greenhorn

Joined: Apr 29, 2013
Posts: 1
Hi All,

I am new to Bouncycastle and trying to create a unsigned PKCS7 file (.p7c). After going through api available, I am able to create the .p7c file using below code.
Now I want to add a metadata in ContentType to this file. I am not getting any API to do so.
Can anyone please help me how can I change/create/re-write a content object and assign it to the CMSSignedData.

................


byte[] metaDataByte = loadFileData(metaData);

CMSProcessable msg = new CMSProcessableByteArray(metaDataByte);

Store certStores = new JcaCertStore(certList);

CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addCertificates(certStores);
CMSSignedData sigData = gen.generate(msg, "BC");


pkcs7File = getPKCS7OutFile(createFile);
outStr = new FileOutputStream(pkcs7File);
outStr.write(sigData.getEncoded());

.....................................................

The above code is giving me output while viewing in openssl as

CMS_ContentInfo:
contentType: pkcs7-signedData (1.2.840.113549.1.7.2)
d.signedData:
version: 1
digestAlgorithms:
<EMPTY>
encapContentInfo:
eContentType: pkcs7-data (1.2.840.113549.1.7.1)
eContent: <ABSENT>
certificates:
d.certificate:
cert_info:

****
I want to add a xml file encoded in uTF-8 to the econent which is <Absent> In previous case. The desired output should be

CMS_ContentInfo:
contentType: pkcs7-signedData (1.2.840.113549.1.7.2)
d.signedData:
version: 1
digestAlgorithms:
<EMPTY>
encapContentInfo:
eContentType: pkcs7-data (1.2.840.113549.1.7.1)
eContent:
0000 - 3c 3f 78 6d 6c 20 76 65-72 73 69 6f 6e 3d 22 <?xml version="
000f - 31 2e 30 22 3f 3e 0d 0a-3c 74 65 73 74 53 74 1.0"?>..<testSt
001e - 72 75 63 74 75 72 65 3e-53 61 6d 70 6c 65 20 ructure>Sample
002d - 4d 65 74 61 64 61 74 61-3c 2f 74 65 73 74 53 Metadata</testS
003c - 74 72 75 63 74 75 72 65-3e tructure>
certificates:




Any help will be highly appreciated.... thanks in advance
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Want to add metadata (XML) into the conent of CMSSignedData!!
 
Similar Threads
javax.naming.Reference incompatible with javax.sql.DataSource
http://xml.apache.org/axis/ HttpErrorCode:401
SOAPAction header problem...Urgent
MQ JMS problem in WSAD
Problem in Jndi LooK up in Was6.1 for MySql Data Source