Unexpected result when encrypting using gcry_pk_encrypt

Erik Nellessen erik.nellessen at informatik.hu-berlin.de
Fri Apr 15 12:41:02 CEST 2016

I am trying to perform an RSA encryption using the function gcry_error_t gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t data, gcry_sexp_t pkey) as described here:

I put a minimal working example in the attachment.

To perform the RSA encryption, I convert strings to mpis (as described on https://gnupg.org/documentation/manuals/gcrypt/MPI-formats.html) and mpis to sexps (as described on https://gnupg.org/documentation/manuals/gcrypt/Working-with-S_002dexpressions.html). This works just as I would expect. When I print the mpis and sexps to the command line, I get the original strings.

Doing the encryption also works without any error. But when I print the result to the command line, I get a lot of cryptographic signs. Now that is in general not a surprise when printing a cipher text, but in this scenario I would have expected a string representing an integer, just like the modulus I used.

I have the impression that I missed or misunderstood something important here. Am I converting my strings in a wrong way? Is there anything going wrong with the encryption?

I am using libgcrypt 1.6.3 on Debian Jessie.

Any kind of help would be appreciated!
Kind regards,
-------------- next part --------------
	gcc -l gcrypt -o mwe mwe.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mwe.c
Type: text/x-csrc
Size: 3875 bytes
Desc: not available
URL: </pipermail/attachments/20160415/bbcb1829/attachment.c>

More information about the Gcrypt-devel mailing list