Code example for X509Certificate

Methods: getEncoded

0
 
	 
	public static String serializeCert(X509Certificate cert) throws CertificateEncodingException {
		StringBuffer buffer = new StringBuffer();
		buffer.append("-----BEGIN CERTIFICATE-----\n");
		buffer.append(Base64.encodeToString(cert.getEncoded(), Base64.DEFAULT));
		buffer.append("\n-----END CERTIFICATE-----");
		return buffer.toString();
	} 
 
	public static X509Certificate unserializeCert(String cert) throws CertificateException {
		CertificateFactory cf = CertificateFactory.getInstance("X.509");
		InputStream in = new ByteArrayInputStream(cert.getBytes() );
		return (X509Certificate) cf.generateCertificate(in);
	} 
	 
}