Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

org.bouncycastle.cms.CMSException: Malformed content.

843811May 29 2007 — edited May 31 2007
Hello!

I have an signed file xxx.p7m

When I try to create a CMSSignedData object, I get the following error:
org.bouncycastle.cms.CMSException: Malformed content.
at org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
at org.bouncycastle.cms.CMSUtils.readContentInfo(Unknown Source)
at org.bouncycastle.cms.CMSSignedData.<init>(Unknown Source)
at ro.sdc.main.BouncyCastleVerify.main(BouncyCastleVerify.java:42)
Caused by: java.lang.IllegalArgumentException: unknown object in factory: org.bouncycastle.asn1.DERApplicationSpecific
at org.bouncycastle.asn1.cms.ContentInfo.getInstance(Unknown Source)
... 4 more


what i want to do i sto extract the content from the signed file

here is my code to accomplish this:

try {
//load signed file
File f = new File(INPUT_FILENAME);
byte[] buffer = new byte[(int)f.length()];
DataInputStream in = new DataInputStream(new FileInputStream(f));
in.readFully(buffer);
in.close();


CMSSignedData signature = new CMSSignedData(buffer);
SignerInformation signer = (SignerInformation)signature
.getSignerInfos().getSigners().iterator().next();
CertStore cs = signature
.getCertificatesAndCRLs("Collection", "BC");
Iterator iter = cs.getCertificates(signer.getSID()).iterator();
X509Certificate certificate = (X509Certificate) iter.next();
CMSProcessable sc = signature.getSignedContent();
byte[] data = (byte[]) sc.getContent();

//verify signature
System.out.println(signer.verify(certificate, "BC"));

//extract data from signed file
FileOutputStream envfos = new FileOutputStream(OUTPUT_FILENAME);
envfos.write(data);
envfos.close();
} catch (Exception e) {
e.printStackTrace();
return ;
}


any ideas why this error occurs?

thank you!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2007
Added on May 29 2007
1 comment
9,434 views