Search code examples
c++encryptiongnupg

How to use GnuPG in a C++ application (not command line tool like)?


I'm planning to write a little application with the basic idea that users are able to share encrypted information with each other. Yes, similar to PGP. Therefore I would like to reuse existing functionality as in GnuPG.

The scenario is the following (in very short): Alice writes a to-do-list. The application encrypts this list with a symmetric key, the symmetric key with Alice's public key and saves the list on the application server. Now Alice wants to share this information with Bob. Therefore Alice uses the application to add Bob to the readers of the to-do-list. The app encrypts the symmetric key of the to-do-list also with Bob's public key and updates the server data.

As already said, I know this is very similar to PGP and I would like to use GnuPG in my C++ app (like one would do with OpenSSL, as can be seen here). But GnuPG is documented like a command line tool. Is there any API documentation how I can use this functionality in a C++ application? Is this even possible?


Solution

  • If you want to use a library to interface GnuPG, GPGME is the way to go without the hassles of parsing GnuPG's output. There are several language bindings for interfacing it.

    If GPGME does not match the required operations or you prefer not using the library (which should be recommended, though), use the --with-colons and --batch options to get a much easier to parse output. Together with gpg-agent you can also have your application prompt for the user's passphrase through already existing implementations, also enabling GUI prompts for the passphrase.