Using output from gpg --list-packets on a key to get the mpi values to generate s-expressions

Werner Koch wk at
Wed Jun 1 10:17:43 CEST 2011

On Wed,  1 Jun 2011 01:56, etiquettesg at said:

> I am trying to use gpg generated public keys to do encryption using
> libgcrypt. I used the list packets command on the key to get me the contents
> of the key and parsed the mpi values into an s-expression. So when I try to

That is not the right way.  --list-packets is a debug command and
subject to change at any time.

A better way to get the public keys in raw format is to use

  gpg --list0-keys --with-key-data --with-colons KEYID

This gives you something like

  uid:f::::1999-03-08::58201FB65551FF[...]81C124::Alice (demo key):

The uid record gives you the algorithm (16 := Elgamal) and the following
pkd records return the key parameters.

Some gpg2 versions support an experimental export option

  gpg2 --export-options export-sexp-format --export KEYID

which returns an S-expression with the key data.  However it is

> numbers in S-expression"? I think list packets is maybe giving me hex
> numbers without the leading zero? If so what do I need to do to get me mpi

Quite possible.



Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.

More information about the Gcrypt-devel mailing list