This week's book giveaway is in the
We're giving away four copies of a choice of
"Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac"
and have Joe Kissell on-line!
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Take Control of Upgrading to Yosemite
Take Control of Automating Your Mac
this week in the
sequence wrong size for a certificate
Joined: Apr 18, 2006
Sep 19, 2006 15:51:00
I am using below lines of code to convert a .cer file to its encoded format (not base64 encoded) :
FileInputStream is = new FileInputStream(new File("c:\\my.cer")); CertificateFactory cf = CertificateFactory.getInstance("X.509"); java.security.cert.Certificate cert = cf.generateCertificate(is); byte buf = cert.getPublicKey().getEncoded(); FileOutputStream os = new FileOutputStream("c:\\my_binary.cer"); os.write(buf); os.close();
However when I try the reverse process of converting back to .cer file using below code:
String file = "c:\\my_binary.cer"; FileInputStream is = new FileInputStream(file); Security.addProvider(new BouncyCastleProvider()); Provider provBC = Security.getProvider("BC"); CertificateFactory cf = CertificateFactory.getInstance("X.509", provBC); java.security.cert.X509Certificate cert = (X509Certificate)cf.generateCertificate(is);
then I am getting error like
: sequence wrong size for a certificate
I tried with Sun's default JCE Provider but not avail. Any thoughts?
Joined: Aug 10, 2006
Sep 23, 2006 06:01:00
You have clearly
stored a certificate in my_binary.cer but rather only the public key. You should change the line
byte buf = cert.getPublicKey().getEncoded();
byte buf = cert.getEncoded();
Nice to meet you.
I agree. Here's the link:
subject: sequence wrong size for a certificate
how to generate x.509 certificate?
InvalidKeyException: IOException : algid parse error, not a sequence
how do i programmatically create a keystore and import my certificate into it?
Help with OCSP Stand Alone Implementation
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014