OpenPGP Code Example: Encrypt with .asc key file


If you receive a public key file (.asc) from your partner, it may be used directly from the OpenPGP component without first importing it into your keyring. The component accepts either a keyring directory or a file when loading a key. For example:

//.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.