Hi,

After looking at other examples, decided to go back to basic tried a simple approach at taking a string argv and passing that to the enc/dec methods, Seems i have the same errorcode as before. I have provided the testfile any help with this one would be very much appreciated.

Regards

Nigel Sollars wrote:
Hi all,

After looking at many examples and reading the OpenSSL book i purchased, I was wondering what the usual culprits are for the errorcode 06065064. By the looks of it, it could be a bad password / key or perhaps a wrong sized outbuf.


Any more information would be highly appreciated,

Thanks in advance
Nigel Sollars
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org


/*
 *      file test1.c
 *
 *      simple round robin test to take 2 inputs, a key & a string to encrypt
 *      Encrypt the string then decrypt priinting out status as we go.
 *
 *      Use the supplied Makefile to build
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/rand.h>

#define input_buf_size 1024
#define output_buf_size 1032

int main(int argc, char *argv[])
{

        if (argc !=2)
        {
                printf("Usage: test1 <stringtoencrypt>\n");
                exit(1);
        }
        
        char *string;

        int encoutlen, decoutlen, enctotallen, dectotallen;

        unsigned char *iv[8];
        unsigned char  *password[16];
        unsigned char enc_outbuf[output_buf_size];
        char enc_inbuf[input_buf_size];
        unsigned char dec_outbuf[input_buf_size];
        char dec_inbuf[output_buf_size];
        EVP_CIPHER_CTX ectx;
        EVP_CIPHER_CTX dctx;

        /*
         * Begin the encode - decode
         *
         * Get our inputs and the random IV
         *
         */

        string = argv[1];

        RAND_bytes(iv, 8);
        RAND_bytes(password, 16);

        printf("Entering Encryption Stage:\n\n");
        printf("String to encrypt: %s\n\n", string);

        EVP_CIPHER_CTX_init(&ectx);


        EVP_EncryptInit(&ectx, EVP_bf_cbc(), password, iv);

        bzero (&enc_inbuf, input_buf_size);

        if(!EVP_EncryptUpdate(&ectx, enc_outbuf, &encoutlen, string, 
strlen(string)))
        {
                printf("Error whilst EncryptUpdate\n");
                return 0;
        }

        if(!EVP_EncryptFinal(&ectx, enc_outbuf + encoutlen, &enctotallen))
        {
                printf("Error Whilst EncryptFinal\n");
                return 0;
        }

        encoutlen += enctotallen;

        printf("Encryption Successful\n\n");
        printf("Entering Decryption Stage\n\n");

        EVP_CIPHER_CTX_init(&dctx);
        EVP_DecryptInit(&dctx, EVP_bf_cbc(), password, iv);

        bzero (&dec_inbuf, output_buf_size);
        bzero (&dec_outbuf, input_buf_size);

        if (!(EVP_DecryptUpdate(&dctx, dec_outbuf, &decoutlen, enc_outbuf, 
output_buf_size)))
        {
                printf("Error Whilst DecryptUpdate\n");
                return 0;
        }

        if (!(EVP_DecryptFinal(&dctx, dec_outbuf + decoutlen, &dectotallen)))
        {
                printf("Error Whilst DecryptFinal\n");
                ERR_print_errors_fp(stdout);
                return 0;
        }

        decoutlen += dectotallen;

        printf("Decryption Successful\n\n");

        printf("Decrypted String is: %s\n", dec_outbuf);

        return 0;

}

Reply via email to