I'm new to OpenSSL and I've been trying to get the following to work for
2 days now.

I'd like decrypt the input file using blowfish and 64 bit blocks.
This code below works fine when decoding text files of any size but with
images the decoded file is larger than the orginal.

I also keep getting an error with EVP_DecryptFinal_ex (Error 2) during
decryption.

What am I missing?
Any kind of help/suggestion will be appreciated!

Daniel


My source code:

int
decryptNew (char* in, char* out)
{
        FILE* inFile;
        FILE* outFile;

        unsigned char* inBuffer;
        unsigned char* outBuffer;
        int outLen, tmpLen;
        long inFileSize;
        int inlen;


        inFile = fopen(in, "rb");
        outFile = fopen(out, "wb");

        inBuffer = (char*) malloc(64);
        outBuffer = (char*) malloc(80);

        EVP_CIPHER_CTX ctx;
        EVP_CIPHER_CTX_init(&ctx);
        EVP_DecryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv);

        memset(inBuffer, 0, 64);

        while((inlen = fread(inBuffer, 1, 64, inFile)) > 0){

                if(!EVP_DecryptUpdate(&ctx, outBuffer, &outLen, inBuffer, 
inlen))
                        printf("error 1\n");

                if(!EVP_DecryptFinal_ex(&ctx, outBuffer, &tmpLen))
                        printf("error 2\n");

                outLen += tmpLen;

                fwrite(outBuffer, 1, outLen, outFile);

                memset(inBuffer, 0, 64);
                memset(outBuffer, 0, 80);
        }

        EVP_CIPHER_CTX_cleanup(&ctx);

        fclose(inFile);
        fclose(outFile);

        free(inBuffer);
        free(outBuffer);

        return 1;
}

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

Reply via email to