Mailing List Archive

newbie question ( RSA with ac )
Hello everybody,

i want to encrypt / decrypt a string with the ac interface

i tried this to encrypt:

g_err = gcry_ac_open( &handle, GCRY_AC_RSA, 0);
assert( !g_err );
g_err = gcry_mpi_scan( &plain, GCRYMPI_FMT_USG, plain_b,
strlen( plain_b ), NULL );
assert( !g_err );
g_err = gcry_ac_data_encrypt( handle, 0, key, plain, &encrypted );
assert( !g_err );
g_err = gcry_ac_data_get_index( encrypted, 0, 0, NULL, &tmp_mpi );
assert( !g_err );
g_err = gcry_mpi_aprint( GCRYMPI_FMT_HEX, &buffer, &len, tmp_mpi );
assert( !g_err );

decrypt:

g_err = gcry_ac_open( &handle, GCRY_AC_RSA, 0);
assert( !g_err );
g_err = gcry_mpi_scan( &enc_mpi, GCRYMPI_FMT_USG, enc_b,
strlen( enc_b ), NULL );
assert( !g_err );
g_err = gcry_ac_data_new( &enc );
assert( !g_err );
g_err = gcry_ac_data_set( enc, GCRY_AC_FLAG_COPY, "a", enc_mpi );
assert( !g_err );
g_err = gcry_ac_data_decrypt( handle, 0, key, &decrypted, enc );
assert( !g_err );
g_err = gcry_mpi_aprint( GCRYMPI_FMT_HEX, &buffer, &len, decrypted );
assert( !g_err );

but the decryption result does not match my string....
can you please tell me what i've done wrong?


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Re: newbie question ( RSA with ac ) [ In reply to ]
> but the decryption result does not match my string....

You probably confuse MPI formats. Your encryption function expects an
USG MPI as input returns a HEX MPI. Your decryption function expects,
again, an USG MPI as inpurt and returns a HEX MPI. Note that USG format
means: raw unsigned integers contained in memory. This has nothing to
do with c-strings (char *). HEX format on the other side means: MPIs
encoded as hexadecimal characters in a c-strings (as in
"123456789ABCDEF").

After modyfing your program to expect HEX MPIs as input in both places,
it simply works here. I send it to off-list.

moritz

--
http://fuglos.org/mo/