Importing a Certificate from a File

See also Exporting a Certificate to a File.
// This method reads a certificate to a file. The certificate can be either // binary or base64 encoded. public static java.security.cert.Certificate importCertificate(File file) { try { FileInputStream is = new FileInputStream(file); CertificateFactory cf = CertificateFactory.getInstance("X.509"); java.security.cert.Certificate cert = cf.generateCertificate(is); return cert; } catch (CertificateException e) { } catch (IOException e) { } return null; }
A certificate can be imported into a keystore using keytool:
> keytool -storepass my-keystore-password -alias myalias -import -file infilename.cer

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.