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

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


On Wed,  1 Jun 2011 01:56, etiquettesg at gmail.com 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.




More information about the Gcrypt-devel mailing list