Sample code for 30+ languages & platforms
Java

RSA Import Private Key

See more RSA Examples

Shows how to select/import a private key for RSA signing or decryption.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkPrivateKey privKey = new CkPrivateKey();
    String password = "secret";
    //  In all Chilkat methods expecting a path, you pass either absolute or relative paths.
    success = privKey.LoadAnyFormatFile("rsaKeys/myTestRsaPrivate.pem",password);
    if (success == false) {
        System.out.println(privKey.lastErrorText());
        return;
        }

    CkRsa rsa = new CkRsa();

    //  Tell the RSA object to use the private key (i.e. import the private key)
    rsa.UsePrivateKey(privKey);
  }
}