seperate public key, private key

Timo Schulz twoaday@freakmail.de
Sun, 19 May 2002 14:37:27 +0200


On Sun May 19 2002; 13:19, Rüdiger Sonderfeld wrote:

> I need to separate the public key and the private key from the GCRY_SEXP 
> struct because I want to save the private key crypted and the public key 
> readable.

I'm not sure if I understand what you mean. The keys should be
separated all of the time. Which means you need to store them in
two GCRY_SEXP contexts from the begin.

 
> How can I separate the keys and how can I put them together again?

You can read the public key packet and put it into one context and
then you do the same with the secret key. Or do you mean you want
to store the public key part of the secret key?

 
> And how can I convert a unsigned char * or char * string into a 
> GCRY_SEXP struct?

Let's say you use a GCRY_MPI which based on the byte buffer,
then you can use the following syntax:

gcry_mpi_scan( &my_mpi, GCRYMPI_FMT_PGP, my_buf, my_buflen );
gcry_sexp_build( &sexp, NULL, "(private-key(elg(p%m)(g%m)(y%m)(x%m)))",
                my_mpi[0], my_mpi[1], my_mpi[2], my_mpi[3] );

...and then you can do the same with the public-key part.


        Timo