Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting pkcs7 format using bouncy castle

843811Sep 5 2008 — edited Sep 9 2008
The following code I am using to get the pkcs7 format, But It is not giving correct output. while validation time its giving problem and if I press signatue porperties that time its freezing. Anyone tell me what is the problem in this code.

String alias = null;
KeyStore keyStore;
byte[] dataToSign; // assum its having pdf file content.
char[] pwd = "password".toCharArray();
keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new FileInputStream(new File("filepath of pfx file")),pwd);
for(Enumeration e = keyStore.aliases() ; e.hasMoreElements() ; ) {
alias = e.nextElement().toString();
}
PrivateKey privKey = (PrivateKey)keyStore.getKey(alias, pwd);
X509Certificate certificate =(X509Certificate) keyStore.getCertificate(alias);

CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
gen.addSigner(privKey, certificate , CMSSignedDataGenerator.DIGEST_SHA1);
ArrayList certList = new ArrayList();
certList.add(certificate);
CertStore certStore = CertStore.getInstance("Collection",
new CollectionCertStoreParameters(certList));
gen.addCertificatesAndCRLs(certStore);
CMSProcessableByteArray process = new CMSProcessableByteArray(dataToSign);
CMSSignedData data = gen.generate(process, null);
byte[] output = data.getEncoded();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 7 2008
Added on Sep 5 2008
3 comments
613 views