hex conversion

Werner Koch wk at gnupg.org
Sat Dec 20 18:58:28 CET 2014


On Thu, 18 Dec 2014 17:06, maxim.suraev at campus.tu-berlin.de said:

> Am I missing something obvious or every user of libgcrypt writes its
> own hex2bin() and bin2hex() functions?

If you need an MPI, you can do that with

  gcry_error_t err;
  gcry_mpi_t n;
  char string[] = "abcdef010203040506070809";

  err = gcry_mpi_scan (&n, GCRYMPI_FMT_HEX, string, 0, 0);
  if (err) 
    print_error ();

gcry_mpi_print and gcry_mpi_aprint can be used to print in hex format.

S-expressions also have an hex format  "(#abcdef010203040506070809)" and
the s-expressions scanning fucntions support that.  For everything elese
you need to do it of your own (look at gnupg/common/convert.c).


Shalom-Salam,

   Werner

-- 
Die Gedanken sind frei.  Ausnahmen regelt ein Bundesgesetz.




More information about the Gcrypt-devel mailing list