java - How do I repackage certificates into pkcs #7 certificate using bouncy castle? -
i have root, intermediate , end entity certificates and, want package in pkcs # 7 format using bouncy castle. how can it?
at first, have read latest rfc on pkcs#7/cms. please click on rfc link read.
now fulfill objective, use bouncycastle. need generate cmssigneddata data. that, need prepare private key , certificate chain. here, going assume, have those. prepare cmsprocessablebytearray.
cmsprocessablebytearray msg = new cmsprocessablebytearray("hello world".getbytes());
now, prepare store list of certificates.
store certs = new jcacertstore(certlist);
then declare cmssigneddatagenerator , add signerinfo , certificates.
cmssigneddatagenerator gen = new cmssigneddatagenerator(); gen.addsignerinfogenerator(new jcasignerinfogeneratorbuilder(......)); gen.addcertificates(certs);
then generate cmssigneddata cmssigneddatagenerator , cmsprocessablebytearray.
cmssigneddata cmsdata = gen.generate(msg, true);
finally write the byte array of cmssigneddata (cmssigneddata.getencoded()
) location .p7b file extension. open file see certificate chain.
Comments
Post a Comment