org.bouncycastle.cms.CMSException: Malformed content.

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!

[1926 byte] By [fulgericaa] at [2007-11-27 5:48:32]
# 1
I have partially solved the problem!the file was in base64 format instead of DERI have converted it using this class org.bouncycastle.util.encoders.Base64
fulgericaa at 2007-7-12 15:34:07 > top of Java-index,Security,Cryptography...