Hi. I've tried in this way too, but still doesn't run correctly.
Here is the code:
#include <stdio.h>
#include <malloc.h>
#include <openssl/evp.h>
void EVP_DES3_encrypt(unsigned char*in, int in_length, unsigned char*password, int password_length, unsigned char** out, int *out_length)
{
unsigned char key[EVP_MAX_KEY_LENGTH];
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char *OUT = NULL;
int OUT_length = 0;
EVP_CIPHER_CTX ctx;
EVP_CIPHER *cipher_type = EVP_des_ede3_cbc();
EVP_MD *hash_type = EVP_md5();
OUT = (unsigned char *) calloc (in_length+8,1);
EVP_BytesToKey(cipher_type,hash_type,NULL,password,password_length,1,key,iv);
EVP_EncryptInit%d\n",EVP_EncryptInit(&ctx,cipher_type,key,iv);
EVP_EncryptUpdate%d\n",EVP_EncryptUpdate(&ctx,OUT,&OUT_length,in,in_length);
EVP_EncryptFinal%d\n",EVP_EncryptFinal(&ctx,OUT,&OUT_length);
*out = OUT;
*out_length = OUT_length;
}
void EVP_DES3_decrypt(unsigned char*in, int in_length, unsigned char*password, int password_length, unsigned char** out, int *out_length)
{
unsigned char key[EVP_MAX_KEY_LENGTH];
unsigned char iv[EVP_MAX_IV_LENGTH];
unsigned char *OUT = NULL;
int OUT_length = 0;
EVP_CIPHER_CTX ctx;
EVP_CIPHER *cipher_type = EVP_des_ede3_cbc();
EVP_MD *hash_type = EVP_md5();
OUT = (unsigned char *) calloc (in_length+8,1);
EVP_BytesToKey(cipher_type,hash_type,NULL,password,password_length,1,key,iv);
EVP_DecryptInit%d\n",EVP_DecryptInit(&ctx,cipher_type,key,iv);
EVP_DecryptUpdate%d\n",EVP_DecryptUpdate(&ctx,OUT,&OUT_length,in,in_length);
EVP_DecryptFinal%d\n",EVP_DecryptFinal(&ctx,OUT,&OUT_length);
*out = OUT;
*out_length = OUT_length;
}
void main()
{
unsigned char password[] = "password";
unsigned char plain[] = "hello mary lou";
unsigned char *cipher = NULL;
unsigned char *plain2 = NULL;
int cipher_length=0;
int plain2_length=0;
EVP_DES3_encrypt(plain, sizeof(plain), password, sizeof(password), &cipher,
&cipher_length);
EVP_DES3_decrypt(cipher, cipher_length, password, sizeof(password), &plain2, &plain2_length);
printf("%s", plain2);
}
Help me please. I'm new in all this big OpenSSL story.
Thanks.
Best regards
andras
| "Greg Stark" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED] 03/20/2001 06:37 PM
|
To: <[EMAIL PROTECTED]> cc: Subject: Re: EVP encrypting |
You don't have to do the cutting; the EVP_* functions do it for you.
_____________________________________
Greg Stark
Ethentica, Inc.
[EMAIL PROTECTED]
_____________________________________
----- Original Message -----
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, March 20, 2001 11:19 AM
Subject: EVP encrypting
Hi.
As I understood, when encrypting a message with a block cipher, the message has to be cutted in pieces, and the EVP_EncryptUpdadate has to be feeded with these pieces.
Do I have to put all the cipher pieces together to obtain the final cipher ?
andras
