Encrypt with OpenPGP Using .asc Public Key File
OpenPGP components allow encryption using a partner's public key file directly, without requiring it to be imported into a keyring. This simplifies key management when working with external .asc key files.
When you receive a public key in .asc format, you can use it directly with the OpenPGP component for encryption or signature verification. The component supports loading either a full keyring directory or a single key file, making it flexible for integration scenarios where keys are provided per partner.
To encrypt data, add the recipient key file to the component, enable ASCII armor if required, set the input message, and call the encrypt operation. The output will be the encrypted message ready for transmission.
// .NET
Openpgp pgp = new Openpgp();
pgp.RecipientKeys.Add(new Key("..\\..\\files\\test@nsoftware.com-public.asc","test@nsoftware.com"));
pgp.ASCIIArmor = true;
pgp.InputMessage = "test";
pgp.Encrypt();
Console.WriteLine(pgp.OutputMessage);
// C++
int ret_code = 0;
char* output;
int len;
OpenPGP pgp;
pgp.SetRecipientKeyCount(1);
pgp.SetRecipientKeyKeyring(0,"..\\..\\files\\test@nsoftware.com-public.asc");
pgp.SetRecipientKeyUserId(0,"test@nsoftware.com");
pgp.SetASCIIArmor(true);
pgp.SetInputMessage("test",4);
ret_code = pgp.Encrypt();
pgp.GetOutputMessage(output,len);
printf(output);
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.