java - Add sign using BouncyCastleProvider -


public class signdata {  public static string execute(string args,string keypass,string certpass,string certpath,string alias_name,string keystore_instance,string algoname) {     string s="";      fileinputstream ksfis = null;     try{             string ksname=certpath;             string spass=certpass;             string alias=alias_name;             string kpass=keypass;             java.security.cert.certificate storecert = null;               java.security.cert.certificate[] certchain = null;             byte[] contentbytes=null;              security.addprovider(new bouncycastleprovider());             arraylist certlist = new arraylist();               //initialize keystore jks file              keystore ks = keystore.getinstance(keystore_instance);             ksfis = new fileinputstream(ksname);              bufferedinputstream ksbufin = new bufferedinputstream(ksfis);               ks.load(ksbufin, spass.tochararray());              // certificate chain keystore              certchain = ks.getcertificatechain(alias);              // load array list retrieved certificates              ( int = 0; < certchain.length;i++)                 certlist.add(certchain[i]);                    // initilize certificate store             certstore certs  = certstore.getinstance("collection", new collectioncertstoreparameters(certlist), "bc");              // extract private key              privatekey priv = (privatekey) ks.getkey(alias, kpass.tochararray());                // signer certificate keystore              storecert = ks.getcertificate(alias);              cmssigneddatagenerator signgen = new cmssigneddatagenerator();             signgen.addsigner(priv, (x509certificate)storecert, cmssigneddatagenerator.digest_sha1);               signgen.addcertificatesandcrls(certs);             contentbytes = args.getbytes();              cmsprocessable content = new cmsprocessablebytearray(contentbytes);               cmssigneddata signeddata = signgen.generate(content,"bc");              byte[] signeddata = signeddata.getencoded();               s=base64utils.base64encode(signeddata);      } catch (exception e) {          logger.error("**********exception while creating digital signature  :" + e.tostring());      }       {          try {                 ksfis.close();         } catch (ioexception e) {             logger.error("**************exception occur while closing file input stream " + e.getmessage());         }      }      return s;  } //end of execute()  } // end of class 

i getting error in following lines.

signgen.addsigner(priv, (x509certificate)storecert, cmssigneddatagenerator.digest_sha1);               signgen.addcertificatesandcrls(certs);  cmssigneddata signeddata = signgen.generate(content,"bc"); 

please give directions.

error message:

the method addsigner(privatekey, x509certificate, string) undefined type cmssigneddatagenerator

the method addcertificatesandcrls(certstore) undefined type cmssigneddatagenerator

the method generate(cmstypeddata, boolean) in type cmssigneddatagenerator not applicable arguments (cmsprocessable, string)

these import statements.

      import java.io.bufferedinputstream;     import com.rbl.utils.base64utils;     import java.io.fileinputstream;     import java.io.ioexception;     import java.security.keystore;     import java.security.privatekey;     //import java.security.signature;     import java.util.*;     import org.bouncycastle.cms.cmsprocessable;     import org.bouncycastle.cms.cmsprocessablebytearray;     import org.bouncycastle.cms.cmssigneddata;     import org.bouncycastle.cms.cmssigneddatagenerator;     import org.bouncycastle.cms.cmstypeddata;     import org.bouncycastle.jce.provider.bouncycastleprovider;     import org.apache.log4j.logger;     


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -