Hello,
> thanks for helping. i tried compiling the source code u gave me but it
> returns the same error, which is:
> [C++ Error] testDes.cpp(23): E2034 Cannot convert 'des_ks_struct
> ( *)[16]' to 'des_ks_struct *' 
> [C++ Error] testDes.cpp(23): E2342 Type mismatch in parameter
> 'schedule' (wanted 'des_ks_struct *', got 'des_ks_struct ( *)[16]').
On Unix this works without problem, maybe try to compile this
using C, not C++ ?

> Anyway to be honest, i don't really know what's happening inside your
> source code (as well as mine). What do all these things 
> ============
> unsigned char key08[] = {0,1,2,3,4,5,6,7};
>     unsigned char key16[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
>     unsigned char key24[] =
> {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23}; 
>     unsigned char key32[] =
> {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
>     unsigned char iv[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
> 
>     unsigned char inbuf[1024]="abcdefg\x01"; 
>     unsigned char outbuf[1024];
> =============
> means? what does all the number represents?  and at the inbuf
> variable, what does \x01 means?
In this code I use only key24 and iv variable.
key24 represents 24 bytes long "secure" des3 key.
It is used to initialize des3 key schedules (in 8 bytes chunks).
I other words, when you use des3 you have to generate exactly 
24 bytes long key. There are methods (like pkcs5) to generate
such sequences from user passwords (like "bob1").
iv variable is called initialization vector and is used in CBC.
DES and DES3 encrypts data in 8 bytes blocks but function
DES_ede3_cbc_encrypt() does not use padding so this block
has 7 bytes of data and one of pad (0x01).
(for 6 bytes of data we should add two bytes 0x0202).
This padding is add for proper decryption with openssl binary.

> I'm really new to all this encryption things, and really hope you
> could help me understand all this. Or if you don't mind, could you
> lead me to anyway i can learn all this? 
You may look at http://en.wikipedia.org/wiki/Block_cipher

In OpenSSL there is high-level API called EVP (envelope)
which is simple and works with padding.
Simple example attached.

After looking at your source second time:
You should not fill key schedule in that way, I assume
that:
        AnsiString myKey = "test1234";
declares eight bytes string but:
        myKey.SubString(1,8).c_str()
        myKey.SubString(9,8).c_str()   <- ???
        myKey.SubString(17,8).c_str()  <- ???

Best regards,
-- 
Marek Marcola <[EMAIL PROTECTED]>
#include <stdio.h>
#include <string.h>

#include <openssl/evp.h>

int main(int argc, char *argv[])
{
	unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
	// unsigned char key[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
	unsigned char iv[] = {1,2,3,4,5,6,7,8};

	unsigned char inbuf[1024];
	unsigned char outbuf[1024];
	int outlen;
	int n;

	EVP_CIPHER_CTX ctx;

	EVP_CIPHER_CTX_init(&ctx);
	EVP_EncryptInit_ex(&ctx, EVP_des_ede3_cbc(), NULL, key, iv);
	// EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv);

	//printf("cipher parameters: \n");
	//printf("    block size: %d\n", EVP_CIPHER_CTX_block_size(&ctx));
	//printf("    key length: %d\n", EVP_CIPHER_CTX_key_length(&ctx));
	//printf("     iv length: %d\n", EVP_CIPHER_CTX_iv_length(&ctx));

	while(1){
		if( (n=fread(inbuf, 1, 128, stdin)) <= 0 ){
			break;
		}
		if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, inbuf, n)){
			return(0);
		}
		fwrite(outbuf, 1, outlen, stdout);
	}
        if(!EVP_EncryptFinal_ex(&ctx, outbuf, &outlen)){
		return(0);
	}
	fwrite(outbuf, 1, outlen, stdout);

	EVP_CIPHER_CTX_cleanup(&ctx);

	return(0);
}

Reply via email to