Public Key encryption
Timo Schulz
twoaday@freakmail.de
Thu, 13 Jun 2002 16:19:13 +0200
On Thu Jun 13 2002; 15:52, Rüdiger Sonderfeld wrote:
> but I don't know! The gcry_pk_encrypt function don't accept unsigned char*
> (only GCRY_SEXP).
>
> What to do?
You can see an example how to do this in gnupg-1.1.2 g10/encode.c
I'll try to give you a basic example:
code snippets:
if( algo == GCRY_PK_ELG || algo == GCRY_PK_ELG_E ) {
rc = gcry_sexp_build ( &s_pkey, NULL,
"(public-key(elg(p%m)(g%m)(y%m)))",
pkey[0], pkey[1], pkey[2] );
}
/* put the data into a simple list */
if ( gcry_sexp_build( &s_data, NULL, "%m", data ) )
BUG ();
/* pass it to libgcrypt */
rc = gcry_pk_encrypt( &s_ciph, s_data, s_pkey );
gcry_sexp_release( s_data );
gcry_sexp_release( s_pkey );
/* extract the MPI values */
GCRY_SEXP list = gcry_sexp_find_token( s_ciph, "a" , 0 );
assert( list );
resarr[0] = gcry_sexp_nth_mpi( list, 1, 0 );
assert( resarr[0] );
gcry_sexp_release ( list );
list = gcry_sexp_find_token( s_ciph, "b" , 0 );
assert( list );
resarr[1] = gcry_sexp_nth_mpi( list, 1, 0 );
assert( resarr[1] );
gcry_sexp_release ( list );
I know it seems to be a little complicated but when you work some
time with it, it's pretty easy ;-).
Timo