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

Foo Lum etiquettesg at
Thu Jun 2 08:11:56 CEST 2011

Thanks for the reply. Is there a way to list the mpi values for the secret
key like the public keys? When I try to the --with-key-data argument on
--list-secret-keys and I don't get the mpi values.


On Wed, Jun 1, 2011 at 5:47 PM, Werner Koch <wk at> wrote:

> 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):
>  sub:f:1024:16:6AE6D7EE46A871F8:1999-03-08::::::e:
>  pkd:0:1024:9C8DD71F57F4BB237D7D99F0EF6C[...]EDB2337:
>  pkd:1:3:7:
>  pkd:2:1021:19E5E632B1A2E70303DEA90F6F36[...]8E1DA90F:
> 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
> experimental.
> > 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.
> Salam-Shalom,
>   Werner
> --
> Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20110602/f420b7f7/attachment.htm>

More information about the Gcrypt-devel mailing list