我有一個X509 Certificate
,我想將它存儲在MySQL DB
而不是保存該文件。因此,我認爲最好將證書轉換爲base64
並存儲它。我已經完成了這個轉換的前進和後退,但是我沒有得到真正的結果。無法將X509證書轉換爲Base64
我使用javax.security.cert.X509Certificate
並導入org.apache.commons.codec.binary.Base64
如下:
X509Certificate cert = X509Certificate.getInstance(new FileInputStream(certFile));
System.out.println("Vigencia: "+cert.getNotAfter());
System.out.println("Inicio: "+cert.getNotBefore());
String cert64 = bytes2String(Base64.encodeBase64(cert.toString().getBytes("UTF-8")));
System.out.println("Cert 64: "+ cert64);
String certRegreso = bytes2String(Base64.decodeBase64(cert64.getBytes()));
System.out.println("Cert Regreso: "+ certRegreso);
X509Certificate certNuevo = X509Certificate.getInstance(certRegreso.getBytes());
它是Apache的commons codec'Base64'嗎? – home