Export keys
This example demonstrates how to export keys from a KeyStore file in DidiSoft OpenPGP Library for .NET. We can export only a public key, only a private key or both in one file. When we export the keys all the sub keys are included too.
C#
using System; using DidiSoft; public class ExportKeys { public void Demo() { // initialize the KeyStore KeyStore ks = new KeyStore(@"DataFiles\key.store", "changeit"); // should the exported files be ASCII or binary bool asciiArmored = false; // export public key having the specified userId // all public sub keys are exported too ks.ExportPublicKey(@"DataFiles\public_key_exported.pkr", "support@didisoft.com", asciiArmored); // export secret key having the specified userId, // this is usually our own key. // all secret sub keys are exported too ks.ExportPrivateKey(@"DataFiles\private_key_exported.skr", "support@didisoft.com", asciiArmored); // export both public and secret key with all sub keys in one file // the file is in ASCII armored format by default ks.ExportKeyRing(@"DataFiles\keypair.asc", "support@didisoft.com"); } }
VB.NET
Imports System Imports DidiSoft Public Class ExportKeys Public Sub Demo() ' initialize the KeyStore Dim ks As New KeyStore("DataFiles\key.store", "changeit") ' should the exported files be ASCII or binary Dim asciiArmored As Boolean = False ' export public key having the specified userId ' all public sub keys are exported too ks.ExportPublicKey("DataFiles\public_key_exported.pkr", _ "support@didisoft.com", _ asciiArmored) ' export secret key having the specified userId, ' this is usually our own key. ' all secret sub keys are exported too ks.ExportPrivateKey("DataFiles\private_key_exported.skr", _ "support@didisoft.com", _ asciiArmored) ' export both public and secret key with all sub keys in one file ' the file is in ASCII armored format by default ks.ExportKeyRing("DataFiles\keypair.asc", "support@didisoft.com") End Sub End Class