28 February 2012

Certificate and Schlumberger Cryptoflex PKI card

re Schlumberger Cryptoflex PKI card
We have the CHVS, its all good.
BTW dont read the public key, do the correct thing and read the certificate, then get the public key from the certificate.
And to send the certificate, dont use certificate.toString
as the helpful forums.oracle say
.."Don't do that. Use the getEncoded() method, and at the receiving end feed that to a CertificateFactory. Depending on your transport you might also need base64-encoding."
...
Just to complete the story: to get a certificate back from encoded byte array:

ByteArrayInputStream bisb = new ByteArrayInputStream(encodedBytes);
CertificateFactory cfb = CertificateFactory.getInstance("X.509");
X509Certificate certb = (X509Certificate)cfb.generateCertificate(bisb);
bisb.close();
print(" X509 back again " + certb.getSigAlgName() );

and the base64 stuff:

To convert X509 certificate to base64 string:

byte[] bCert = certificate.getEncoded();
String sCert = javax.xml.bind.DatatypeConverter.printBase64Binary(bcert);
And to convert back:
String sCert = XML extract the X509Certificate object...
byte[] bencoded = javax.xml.bind.DatatypeConverter.parseBase64Binary(sCert); // Converts the string argument into an array of bytes.

No comments:

Post a Comment