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!

Converting Certificates

843811Jul 5 2006 — edited Jul 6 2006
Hello to all Java Cryptography fans!!!

I have a little problem so if anyone knows how to solve it, I would appreciate it....

I'm writing a stand-alone e-mail program which implements cryptographically enhanced e-mail in accordance with S/MIME standard. Program is very simple, form, few text fields, text area, and three buttons Send, Sign and Encrypt...

When user clicks on Send button and for example, if a Sign button is disabled, then a user have chosen to sign message, so the application then accesses GemSafe smart card, reads PrivateKey and java.security.cert.Certificate from it. Simultaneously, application creates SMIMESignedGenerator and calls addSigner(java.security.PrivateKey, java.security.cert.X509Certificate, String OID) method.

Code:
...
KeyStore ks = KeyStore.getInstance("PKCS11");
char[] pin = "password".toCharArray();
ks.load(null, pin);
...
Enumeration e = ks.aliases();
String alias = String.valueOf(e.nextElement());
PrivateKey pk = (PrivateKey)ks.getKey(alias, pin);
java.security.cert.Certificate cer = ks.getCertificate(alias);
...
SMIMESignedGenerator gen = new SMIMESignedGenerator();
gen.addSigner(pk. cer, SMIMESignedGenerator.DIGEST_SHA1);
...
Of course, I configured BouncyCastle and SunPKCS11 providers earlier...

There is my problem....
How to convert Certificate to X509Certificate? Does anyone have sample code? Can I do that without exporting certificate to a file?

Thanks!!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 3 2006
Added on Jul 5 2006
2 comments
154 views