Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6244561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:20:51+00:00 2026-05-24T12:20:51+00:00

I am trying to create a file containing a pkcs 7 block. In this

  • 0

I am trying to create a file containing a pkcs 7 block. In this container, I need my public key and my signer info (no signed data!!!). I have already tried several alternatives without any luck. This is my code:

First the signature info:

 List<X509Certificate> certs = new List<X509Certificate> { cert };
 IX509Store x509Certs = X509StoreFactory.Create(
      "CERTIFICATE/COLLECTION",
      new X509CollectionStoreParameters(certs));

 var ias = new IssuerAndSerialNumber(cert.IssuerDN, cert.SerialNumber);
 SignerIdentifier sid = new SignerIdentifier(ias);
 AlgorithmIdentifier algoDigId = new AlgorithmIdentifierCmsSignedGenerator.DigestSha1);
 AlgorithmIdentifier algoCryptId = new AlgorithmIdentifier(CmsSignedGenerator.EncryptionRsa);

 SignerInfo si = new SignerInfo(sid, algoDigId, null, algoCryptId,
                                      new DerOctetString(contentSignature), null);

the contentSignature byte[] contains a signed digest for some info.

Now, when I try to create the SignedData, everything goes down

  var signedContent = new ContentInfo(CmsObjectIdentifiers.Data, DerNull.Instance);
  CmsSignedData csd = new CmsSignedData(signedContent);

I am not trying to send info, this is only for key exchange and verification purposes. I believe this is a valid scenario but somehow this does not work.

Thanks for your help.

UPDATE:

more context.

I am trying to sign a JAR from a .Net executable. I have pretty much done the rest of the process but jarsigner creates a pkcs7 file with:

  • ContentInfo set to type Data and no content. So far, making new ContentInfo( CmsObjectIdentifiers.Data, null) just throws an exception while adding the content info to the CmsData

  • A SignerInfo is added, this SignerInfo includes a signature previously derived from the JAR’s content.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:20:52+00:00Added an answer on May 24, 2026 at 12:20 pm

    As this question is specifically related to signing an APK / JAR file, I will answer in that context.

    Assuming that:

    You have performed all the following setup steps:

    1. Generated a valid MANIFEST.MF
    2. Generated a valid CERT.SF
    3. Have a valid PFX file loaded into an X509Certificate2 variable named “cert”
    4. Have the binary contents of the CERT.SF file in a byte array named “manifestSFBytes”

    The following code will generate a valid detached pkcs7 signature which is effectively your CERT.RSA content:

    string OID_DATA = "1.2.840.113549.1.7.1";
    
    // setup the data to sign
    ContentInfo content = new ContentInfo( new Oid( OID_DATA ), manifestSFBytes );
    SignedCms signedCms = new SignedCms( content, true );
    CmsSigner signer = new CmsSigner( SubjectIdentifierType.IssuerAndSerialNumber, cert );
    
    // create the signature
    signedCms.ComputeSignature( signer );
    byte[] data = signedCms.Encode();
    

    This code relies on the System.Security.Cryptography.Pkcs namespace and does not require BouncyCastle.

    What is going on here is that the raw content (signature file binary data) is hashed and signed in one go by the ComputeSignature() call.

    Therefore no “null ContentInfo” tricks are necessary i.e. the ContentInfo contains the raw data to be signed and hashed unlike the Java implementation which signs and hashes the content prior to PKCS7 generation.

    HTH

    -(e)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a record containing the path to a file. The
I am trying to create an XML file based on data fields from a
I am trying to create an XML file to conform to someones XSD this
I'm trying to use PHP to create a file containing a list of phone
I have an XML file containing seed data that I'm trying to load into
I've been able to create a signed CAB file for web deployment containing my
I am trying to write a tool to create a zip file containing all
I am trying to create a file in the /tmp directory (working on a
I am trying to create a file using File newFile = new File(myFile); However
I'm trying to create a folder and create a file within it. Whenever i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.