Mailing List Archive

format of encrypted data in sexpr
Hi,

I'm encoding a file in chunks of 128 Bytes (1024 bit rsa with
public/private key encryption) and everything seems to work well.

The gcry_sexp_sprint function below sometimes returns a hex string
(enclosed with hashmarks) and sometimes a string (enclosed in double
quotes) in some random order for reasons not immediately obvious to
me.

Is there a way to specify (force) one of the two formats (I'd
much prefer the hex string to the regular string)?

Here is the relevant part of the code I'm using:

sprintf(buf, "(data (flags raw) (value %s))", hexstring);
err = gcry_sexp_build (&sexp, NULL, buf);
err = gcry_pk_encrypt (&decr, sexp, pkey);
gcry_sexp_sprint (decr, GCRYSEXP_FMT_ADVANCED,
buf, MAXLENGTH);
extract_a_from_sexp (decr, decryptstr);

As I said, everything works. It's just a little tedious to deal with
the string representation (especially as it sometimes contains escaped
characters, like hex values or newlines etc.).

Thanks,
Orm

_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Re: format of encrypted data in sexpr [ In reply to ]
On Thu, 28 May 2009 22:42, o.finnendahl@mh-freiburg.de said:

> The gcry_sexp_sprint function below sometimes returns a hex string
> (enclosed with hashmarks) and sometimes a string (enclosed in double
> quotes) in some random order for reasons not immediately obvious to
> me.

That is just a human readable format which uses a heuristic to decide
how to print it out. See libgcrypt/src/sexp.c:suitable_encoding .

For machine based parsing it is way easier to use the canonical
S-expression format; see http://people.csail.mit.edu/rivest/sexp.html
for details on S-expressions.

> gcry_sexp_sprint (decr, GCRYSEXP_FMT_ADVANCED,

Use GCRYSEXP_FMT_CANON . gnupg/common/sexp-parse.h has fucntions to
parse a canonical encoded S-expression.


Shalom-Salam,

Werner

--
Die Gedanken sind frei. Auschnahme regelt ein Bundeschgesetz.


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel