I am trying to use sign.c example to sign a file with my own DSA
certifiacate and private key file, and EVP_SignFinal (see below fails) with
EVP_R_WRONG_PUBLIC_KEY_TYPE. Does this mean that files do not match or is
something not set? I am pretty sure that those two files were created as a
set and worked for client server communication. Any thoughts ideas?

        int err;
        unsigned int sig_len;
        unsigned char sig_buf [4096];
        
        EVP_MD_CTX     md_ctx;
        FILE *          fp;
        X509 *                  x509;
        
        RAND_screen();


        /* Just load the crypto library error strings,
        * SSL_load_error_strings() loads the crypto AND the SSL ones */
        /* SSL_load_error_strings();*/
        ERR_load_crypto_strings();
        
        /* Read private key */
        
        fp = fopen (keyfile, "r");
        if(fp==NULL) // error check
        {
                ERR_print_errors_fp(stderr);
                return FALSE;
        }

                EVP_PKEY* privateKey = NULL; 
                // read the private key from the pem file, convert it into
an 
                // EVP_PKEY and store it in privateKey
                privateKey = (EVP_PKEY*)PEM_ASN1_read ((char
*(*)())d2i_PrivateKey,
                        PEM_STRING_EVP_PKEY,
                        fp,
                        NULL, NULL, NULL);
                fclose(fp);

        /* Do the signature */
        char *pFileContents = NULL;
        CFile file;
        BOOL bResult = TRUE;
        DWORD dwLength;
        if (!file.Open(filePath, CFile::modeRead | CFile::shareExclusive |
CFile::typeBinary))
        {
                return FALSE;
        }
        TRY
        {
                dwLength = file.GetLength();
                pFileContents = new char[dwLength];
                DWORD dwNumRead = file.Read(pFileContents, dwLength);
        }
        CATCH(CFileException, fe)
        {
        }
        END_CATCH
        file.Close();

        EVP_SignInit   (&md_ctx, EVP_sha1());
        EVP_SignUpdate (&md_ctx, pFileContents, dwLength);
        
        sig_len = sizeof(sig_buf);
        err = EVP_SignFinal (&md_ctx, sig_buf, &sig_len, privateKey);
        
        if (err != 1) {
                ERR_print_errors_fp(stderr);
                return FALSE;
        }
        
        EVP_PKEY_free (privateKey);

-----Original Message-----
From: 263 [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 10, 2000 11:45 PM
To: [EMAIL PROTECTED]
Subject: Re: How to encrypt and sign a file?


Use demos/sign/sign.c as an example.

Hazel

> Is there a way and a sample to sign a file and then verify file's
signature?
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> User Support Mailing List                    [EMAIL PROTECTED]
> Automated List Manager                           [EMAIL PROTECTED]
> 

 ______________________________________________
  Miss Yuhang Gao
  Network Center, Computer Dept.
  Southeast University,
  Nanjing, Jiangsu,
  P.R.China
  210096
______________________________________________________________________
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