質問

I made a terrible mistake saving a list of X509Certificates using the "toString()" method. The library used is "javax.net.ssl.java.security.cert.X509Certificate". I'd like to recover them and save them properly using either a PEM or DER format but all I can find on StackOverflow is about reading proper DER/PEM certs.

The way they look currently on the files is:

http://www.heypasteit.com/clip/18XK

Any help will be much appreciated.

UPDATE FOR REFERENCE:

That's the way I'm storing it for Android:

protected static String convertToPem(X509Certificate cert) throws CertificateEncodingException {

    String cert_begin = "-----BEGIN CERTIFICATE-----\n";
    String end_cert = "-----END CERTIFICATE-----";

    String pemCert = "";

    byte[] derCert;
    try {
        derCert = cert.getEncoded();
        String pemCertPre = Base64.encodeToString(derCert, Base64.DEFAULT);
        pemCert = cert_begin + pemCertPre + end_cert;
    } catch (java.security.cert.CertificateEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return pemCert;

}

役に立ちましたか?

解決

You can't. It's too late. There's not enough information in the toString() method's output.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top