Hi Darryl,
here is a code example how to store DSA private key in DER format and load
it back from the file.
It's a better idea to store the private key with a password...
maybe someone will be happy to add some words about it.
Ohad.


******************* STORE **********************

        DSA                     *dsa;
        char                    buf[1024];
        unsigned char   *ptr;
        unsigned int    DER_size;
        unsigned int    DER_to_file;
        FILE                    *f;
        int                     CounterRet;
        unsigned long   h_ret;

        dsa = DSA_generate_parameters(1024, NULL, 0, &CounterRet, &h_ret,
NULL, NULL);
        if (dsa == NULL)
                return ERROR;

        if (DSA_generate_key(dsa) != 1)
                return ERROR;

        // Store the private key (in DER encoding binary) in the specified
file.
        ptr = buf;
        DER_size = i2d_DSAPrivateKey(dsa, &ptr);
        if (DER_size == 0)
        {
                DSA_free(dsa);
                return ERROR;
        }
        f = fopen("privatekey","wb");
        if (f == NULL)
        {
                return ERROR;
        }
        DER_to_file = htonl(DER_size);
        fwrite(&DER_to_file,sizeof(int),1,f);
        fwrite(buf,sizeof(char),DER_size,f);
        fclose(f);


******************* LOAD **********************

        char                    buf[1024];
        unsigned char   *ptr;
        unsigned int    DER_size;
        FILE                    *f;

        ptr = buf;
        f = fopen("privatekey","rb");
        if (f == NULL)
                return ERROR;
        fread(&DER_size,sizeof(int),1,f);
        DER_size = ntohl(DER_size);
        fread(buf,sizeof(char),DER_size,f);
        fclose(f);
        if (d2i_DSAPrivateKey(&priv_dsa, &ptr, DER_size) == NULL)
                return ERROR;




-----Original Message-----
From: Darryl Wagoner [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 01, 2001 12:14 PM
To: [EMAIL PROTECTED]
Subject: Storing and reading DSA information.


Greetings,

I am trying to use the DSA functions in the crypto library.  Do someone
have some examples of storing and reading DSA information from a file
or can point me in the right direction?

Thanks
Darryl
73 DE WA1GON

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to