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 7647035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:21:47+00:00 2026-05-31T10:21:47+00:00

I was wondering what signature algorithm (digestOID) BouncyCastle uses by default if you do

  • 0

I was wondering what signature algorithm (digestOID) BouncyCastle uses by default if you do not specify it explicitly like like in the code below:

  List             certList = new ArrayList();
  CMSTypedData     msg = new CMSProcessableByteArray("Hello world!".getBytes());

  certList.add(signCert);

  Store           certs = new JcaCertStore(certList);

  CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
  ContentSigner sha1Signer = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(signKP.getPrivate());

  gen.addSignerInfoGenerator(
            new JcaSignerInfoGeneratorBuilder(
                 new JcaDigestCalculatorProviderBuilder().setProvider("BC").build())
                 .build(sha1Signer, signCert));

  gen.addCertificates(certs);

  CMSSignedData sigData = gen.generate(msg, false);

Below is the code example for which I am wondering as you see there is no digestOID(SHA1withRSA) so what type of signature does it use:

import java.io.*;
import java.util.*;
import java.security.*;
import java.security.Security;
import java.security.cert.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.cms.*;


/* Create CMS/pkcs #7 signature using BC provider
                 M. Gallant  07/02/2003  */

class BCSignFile {
 static final boolean DEBUG = false;

 public static void main(String args[]) {
 System.out.println("");

  if (args.length < 4)
    usage();

 Security.addProvider(new BouncyCastleProvider());

 String INFILE   = args[0]; // Input file to be signed
 String KEYSTORE = args[1]; // Java 2 keystore file
 String ALIAS    = args[2]; // Java 2 key entry alias
 String PSWD     = args[3]; // keystore password

 // ---- in real implementation, provide some SECURE way to get keystore
 // ---- password from user! -------

 KeyStore keystore = null;
 PublicKey pub = null;
 PrivateKey priv = null;
 java.security.cert.Certificate storecert = null;
 java.security.cert.Certificate[] certChain = null;
 ArrayList certList = new ArrayList();
 CertStore certs =null;

 try{
   keystore = KeyStore.getInstance("JKS");
   keystore.load(new FileInputStream(KEYSTORE), PSWD.toCharArray());

   certChain = keystore.getCertificateChain(ALIAS);
   for ( int i = 0; i < certChain.length;i++)
    certList.add(certChain[i]);      
   certs = CertStore.getInstance("Collection", new     CollectionCertStoreParameters(certList), "BC");

       priv = (PrivateKey)(keystore.getKey(ALIAS, PSWD.toCharArray()));

   storecert = keystore.getCertificate(ALIAS);
   pub = keystore.getCertificate(ALIAS).getPublicKey();
 }
 catch(Exception exc){
  System.out.println("Problem with keystore access: " + exc.toString()) ;
  return;
  }


  if(DEBUG){
   System.out.println("Public Key Format: " + pub.getFormat()) ;
   System.out.println("Certificate " + storecert.toString()) ;
  }

  FileInputStream freader = null;
  File f = null;

    //------  Get the content data from file -------------
      f = new File(INFILE) ;
  int sizecontent = ((int) f.length());
  byte[] contentbytes = new byte[sizecontent];

  try {
    freader = new FileInputStream(f);
    System.out.println("\nContent Bytes: " + freader.read(contentbytes, 0,     sizecontent));
    freader.close();
   }
  catch(IOException ioe) {
    System.out.println(ioe.toString());
    return;
    }


// --- Use Bouncy Castle provider to create CSM/PKCS#7 signed message ---
 try{
  CMSSignedDataGenerator signGen = new CMSSignedDataGenerator();
  signGen.addSigner(priv, (X509Certificate)storecert,     CMSSignedDataGenerator.DIGEST_SHA1);
  signGen.addCertificatesAndCRLs(certs);
  CMSProcessable content = new CMSProcessableByteArray(contentbytes);

  CMSSignedData signedData = signGen.generate(content,"BC");
  byte[] signeddata = signedData.getEncoded();
  System.out.println("Created signed message: " + signeddata.length + " bytes") ;
  FileOutputStream envfos = new FileOutputStream("BCsigned.p7s");
                  envfos.write(signeddata);
  envfos.close();
 }
 catch(Exception ex){
  System.out.println("Couldn't generate CMS signed message\n" + ex.toString()) ;
 }
}


 private static void usage() {
  System.out.println("Usage:\n java BCSignFile  <contentfile> <keystore> <alias>     <keypasswd>") ;
  System.exit(1);
 }
    }
  • 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-31T10:21:49+00:00Added an answer on May 31, 2026 at 10:21 am

    The relevant line is this:

    signGen.addSigner(priv, (X509Certificate)storecert, CMSSignedDataGenerator.DIGEST_SHA1);
    

    This line specifies that the digest-algorithm will be SHA-1 and that the signing-algorithm will be decided based on the type of the private key in priv.

    If priv contains an RSA key, it will sign using PKCS#1 v.1.5 with SHA-1 (“SHA1withRSA”). You can look in the source of CMSSignedGenerator.getEncOID() to see what happens with other types of private key.

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

Sidebar

Related Questions

Being new to ASP.NET MVC, I've been wondering about the signature of Controller methods.
I am wondering why the following code: @Html.DropDownList(Classification.Nationality.NationalityId, Model.Nationalities, new { @size = 10,
all, I have some problem installing my apk file in code. Wondering if anyone
The code below is just an example. The predicate of string is a I'm
I would like to know how one achieves the following signature. I have read
I am wondering OAuth signature is related only to URL or related to something
Wondering what the best / good way of doing this would be in jQuery.
Wondering if any of you can help me: I've made a signup modal that
Wondering if someone could please explain the difference between these two queries and advise
Wondering if someone could help me. I have next to no knowledge with Ajax,

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.