Importing a Certificate from a File - Java Security

Java examples for Security:Certificate

Description

Importing a Certificate from a File

Demo Code

import java.io.File;
import java.io.FileInputStream;
import java.security.cert.CertificateFactory;

public class Main {
  public static java.security.cert.Certificate importCertificate(File file) {
    try {//from  www .  j  a va2  s.  com
      FileInputStream is = new FileInputStream(file);

      CertificateFactory cf = CertificateFactory.getInstance("X.509");
      java.security.cert.Certificate cert = cf.generateCertificate(is);
      return cert;
    } catch (Exception e) {
    }
    return null;
  }

}
> keytool -storepass my-keystore-password -alias myalias -import -file infilename.cer

Related Tutorials