On Mon, Aug 10, 2009, MusicAndy wrote:

> 
> Thanks for your help so far, but still cannot get this working...
> 
> Here is my latest code.
> 
> I am trying to emulate something that should be simple, which can be
> decrypted using
> openssl des3 -d -nosalt -k "1" -in <source filename> -out <destination
> > filename>
> 
> 
> 
>     EVP_CIPHER_CTX ctx;
>     EVP_CIPHER_CTX_init(&ctx);
>     const EVP_CIPHER* cipher=EVP_des_ede3_cbc();
>     const EVP_MD *dgst=EVP_sha1();
> 
>     u_char pass[8]; 
> //    char salt[8]; 
> 
>     unsigned char key[EVP_MAX_KEY_LENGTH]; 
>     unsigned char iv[EVP_MAX_IV_LENGTH]; 
> 
> 
> 
> //    printf("key_len: %d\n", cipher->key_len); 
>   //  printf(" iv_len: %d\n", cipher->iv_len); 
> 
>       strcpy((char*)pass, "1"); 
> //    strcpy((char*)salt, "ATHENA.MIT.EDUraeburn"); 
> 
> 
>       EVP_BytesToKey(cipher,dgst,NULL,pass, 1, 3, key, iv);
> 
>       unsigned char* desBuf = new unsigned char[numbytes];
> 
>       EVP_EncryptInit_ex(&ctx, cipher, NULL,key,iv);
> 

The count parameter must be 1, not 3 for compatibility with the enc program.

Also make sure the file is opened in binary mode ("rb").

You can use the -P option to "enc" and print out the key, IV in your programe
to ensure they are identical.

Steve.
--
Dr Stephen N. Henson. OpenSSL project core developer.
Commercial tech support now available see: http://www.openssl.org
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to