Load the OpenPGP keyrings
While SecureBlackbox provides several different ways to load a key from a file, we recommend to always use the keyring-based method explained below. The primary reason for using this method is its high tolerance to a variety of peculiarities of third-party PGP implementations. Other methods - like the one based on the LoadFromFile() function exported by TElPGPPublicKey and TElPGPSecretKey components - only work with properly crafted key material and may fail if the key is not formatted correctly.
TElPGPKeyring keyring = new TElPGPKeyring(); keyring.Load("LukesPublicKey.pkr", "LukesSecretKey.skr", true);
If your keypair is contained in a single file, or if you only want to load the public part of the key, please pass null or empty string in the unneeded parameter:
keyring.Load("LukesKeypair.bin", null, true);The last parameter ('Clear') set to true tells the keyring object to remove all the keys already present in the keyring before loading the key. It doesn't play a big role if the key is loaded into a brand new keyring object.
The same approach can be used if your keyring stores both public and secret keys in one file. In fact, TElPGPKeyring treats both PublicKeysFile and SecretKeysFile in an absolutely equal way, picking all the keys it can (public and secret) from both. I.e. you can easily swap the public and secret file paths in the first call above with no apparent effect on its outcome.
Once the key is loaded, it can be accessed via the keyring's PublicKeys and SecretKeys properties.