Contact Us Forum Customers Area

DidiSoft Ltd.

Import keys

<< Back to Java examples

This example demonstrates how to import existing keys from standalone files into a KeyStore object.

import com.didisoft.pgp.KeyStore;
 
public class ImportKeys {
 public static void main(String[] args) throws Exception {
  // initialize the KeyStore. The key store file may not exist
  // and subsequent operations will create it
  KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");
 
  // import private key
  keyStore.importPrivateKey("private.asc", "changeit");
 
  // import public key
  keyStore.importPublicKey("public.asc");
 
  // imports key ring file. The file may contain public, private or 
  // both type of keys if it is in ASCII armored format
  keyStore.importKeyRing("keypair.asc");	
 }
}

<< Back to Java examples