Contact Us Forum Customers Area

DidiSoft Ltd.

Import keys

<< Back to .NET examples

If we already have OpenPGP keys from our partners or generated through another OpenPGP compatible software (e.g. PGP (r) Desktop or GnuPG) we can use them directly as they are or import them in a KeyStore file (see getting started guide for more details). The example below demonstrates how to import a public key, a private key and a key pair (both keys) with OpenPGP Library for .NET

C#

using System;
using DidiSoft;
 
public class ImportKeys
{
   public static void Demo()
   {
      // initialize the key store
      KeyStore keyStore = new KeyStore("pgp.keystore", "changeit");       
 
      keyStore.ImportPublicKey("public.pkr");
 
      String privateKeyPassword = "changeit";
      keyStore.ImportPrivateKey("private.skr", privateKeyPassword);   
 
      keyStore.ImportKeyRing("keyring.asc");
    }
}

VB.NET

Imports System
Imports DidiSoft
 
Public Class ImportKeys
 Public Shared Sub Demo()
   ' initialize the key store
   Dim keyStore As New KeyStore("pgp.keystore", "changeit")
 
   keyStore.ImportPublicKey("public.pkr")
 
   String privateKeyPassword = "changeit"
   keyStore.ImportPrivateKey("private.skr", privateKeyPassword)
 
   keyStore.ImportKeyRing("keyring.asc")
 End Sub
End Class

Note that with the ImportKeyRing method we can also import a private key file without specifying the private key password, but anyway in order to use it we should pass its password in the decryption and signing methods

<< Back to .NET examples