Problem with public key encription

Madelman madelman at iname.com
Thu Mar 3 13:44:33 CET 2005


Hi,

i'm having a problem when trying to encrypt the session key with the public key.

The code in question is:

--------------
// generate session key
sessionKey = new unsigned char[16];
gcry_randomize(sessionKey, longClaveSesion, GCRY_STRONG_RANDOM);
// convert session key to S-Expression
gcry_sexp_build(&data, NULL, "(data (flags raw)(value %b))", (size_t) 16, sessionKey);
// firmamos con la clave publica del destinatario
err = gcry_pk_encrypt(&encryptedSessionKey, data, destinationKey);
--------------

and the returned error is Invalid object. But this only occurs sometimes, the rest
of the time everything works ok. I debugged it and saw the problem was dependant on
the value of the session key, so in general it works ok but with some values of the
session key it fails. I tracked it down to the function gcry_sexp_nth_mpi, which doesn't
return a correct mpi when called with some of my values, but i can't find the problem.

These are some of the values i got working and not:

-------------------
(data
  (flags raw)
  (value #23F9C6B31389B304F44083B1F7C4E58C#)
)
Result: Success

(data
  (flags raw)
  (value #81ACBB98319D5EA67F63E28FC234790B#)
)
Result: Invalid object

(data
  (flags raw)
  (value #D2440A26F494E23DB65F7D9794DB88CA#)
)
Result: Invalid object
-------------------

Does anybody have any clue about what I'm doing wrong?

Thanks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 1822 bytes
Desc: S/MIME Cryptographic Signature
Url : /pipermail/attachments/20050303/a3c0ed6b/smime.bin


More information about the Gcrypt-devel mailing list