Java security: get certificate from string (byte array) 


May 23, 2011 12:07:59    Last update: May 23, 2011 12:09:42
You can construct a object from a string or byte array. Byte array is cleaner because for string you also have to know the character encoding.
// import;
// import;
String certString = "some string representing a X.509 certificate";
Certificate myCert = CertificateFactory
                                        // string encoded with default charset
					new ByteArrayInputStream(certString.getBytes())

If the certificate string is encoded in "UTF-8", the ByteArrayInputStream should be created with:
new ByteArrayInputStream(certString.getBytes("UTF-8"));
Share |
| Comment  | Tags