Java
Chilkat2 Java
Import a Certificate (.cer file) into a Windows Certificate Store
See more Certificates Examples
Demonstrates how to import a certificate (without private key) into a Windows certificate store.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.CertStore;
import com.chilkatsoft.chilkat2.ChilkatException;
public class ChilkatExample {
public static void main(String[] args) {
Cert cert = new Cert();
try {
cert.loadFromFile("qa_data/certs/example.cer");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
CertStore certStoreCU = new CertStore();
boolean readOnlyFlag = false;
// "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
try {
certStoreCU.openWindowsStore("CurrentUser", "My", readOnlyFlag);
} catch (ChilkatException e) {
System.out.println("Failed to open the CurrentUser/My certificate store for read/write.");
return;
}
// Import the certificate into the CurrentUser/My certificate store.
try {
certStoreCU.addCertificate(cert);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Imported " + cert.getSubjectCN());
System.out.println("Success.");
}
}