Hi everybody,
i'm new with the openssl libs (0.9.8a), I try to develop a program wich need
to produce a file that can be decrypted with the openssl command line tool.
i choosed des_ede3_cbc as the syemtric algorithm.
the "encryption" part of my code is given at the end of this post.
I verified with my debugger that the key/iv generated via EVP_BytesToKey ()
is the same via my program and with the openssl comand line tool.
the file crypted with my program and with the openssl comand line tool
doesn't have many diffence (but they differs!) I inspected the first 384
bytes of a 2 854 802 byte long file with a binary editor.
It show that at the offset 0x45 on my file there is one byte added (0x0d)
and at the offset 0x4d there is also another 0x0d added that's all for the
first 384 bytes!
I tryed with a 128 byte buffer and a 512 byte buffer I obtained exactly the
same output...
so it is impossible to decrypt my file with openssl ! Does anyone can help
me???
Thanks
Ronan
------------------------------------------------------------
#define ALG EVP_des_ede3_cbc()
#include <openssl/evp.h>
(...)
unsigned char * buf;
unsigned char * ebuf;
const unsigned char salt[8]={0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
int ebuflen; /* rc; */
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char key[EVP_MAX_KEY_LENGTH];
FILE *fpClearFile, *fpCryptFile;
size_t readlen;
buf = (unsigned char *)malloc(BUFLEN);
ebuf = (unsigned char *)malloc(BUFLEN+8);
err = fopen_s(&fpClearFile,argv[4], "rb");
err += fopen_s(&fpCryptFile,argv[5], "w");
if (err)
{
_tprintf(_T("Error opening %s file!\n"),argv[4]);
}
fwrite("Salted__",sizeof(char),8,fpCryptFile);
fwrite(salt,sizeof(char),8,fpCryptFile);
EVP_CIPHER_CTX ectx;
EVP_BytesToKey(ALG, EVP_md5(), salt, passprhaseKey, passprhaseKey_len-1,
1, key, iv);
EVP_CIPHER_CTX_init(&ectx);
EVP_CipherInit_ex(&ectx, ALG, NULL, key, iv, ENCRYPT);
while (!feof(fpClearFile))
{
readlen = fread(buf,sizeof(*buf),BUFLEN,fpClearFile);
EVP_CipherUpdate(&ectx, ebuf, &ebuflen, buf, readlen);
fwrite(ebuf, sizeof(*ebuf),ebuflen,fpCryptFile);
}
EVP_CipherFinal_ex(&ectx, ebuf, &ebuflen);
EVP_CIPHER_CTX_cleanup(&ectx);
fwrite(ebuf, sizeof(*ebuf),ebuflen,fpCryptFile);
fclose(fpClearFile);
fclose(fpCryptFile);
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]