Search code examples
bouncycastlesignedpkcs#7oid

How to edit Java BC CMSSignedData PKCS#7?


I have a BouncyCastle CMSSignedData object represented as PKCS#7 signed data.

How can I edit the CMSSignedData to remove the value (octet string) of contentInfo (OID 1.2.840.113549.1.7.1)?


Solution

  • Method CMSSignedDataGenerator.generate() is using CMSObjectIdentifiers.signedData [1.2.840.113549.1.7.2] as contentType when constructing a CMSSignedData object. You could rewrite CMSSignedDataGenerator.java or better craft your own generator class and use a different ObjectIdentifier.

    The bcpkix sources are available at bouncycastle.

    Note that id-signedData is the official RFC 5652 content type for signed-data CMS objects:

    id-signedData OBJECT IDENTIFIER ::=
    { iso(1) member-body(2) us(840) rsadsi(113549) pkcs(1) pkcs7(7) 2 }