It's working properly
I execute program and output is  :
[EMAIL PROTECTED]
Hello World!

what is your problem?


On Mon, Jun 30, 2008 at 4:12 PM, Vijay Kotari <[EMAIL PROTECTED]>
wrote:

> I not too sure about using the same context for both decryption and
> encryption. It says in the man pages that *
>
> EVP**_**CIPHER**_**CTX**_**cleanup()* clears all information from a cipher
> context and free up any allocated memory associated with it.
>
> So, I think you should probably use different contexts, one for decrypting
> and another for encrypting. But I am not too sure, if your code does not
> work, then you probably should try it this way, because everything else
> looks ok.
>
>
> Regards,
> Vijay K.
>
>
>
> On Sat, Jun 28, 2008 at 5:01 PM, Razack <[EMAIL PROTECTED]> wrote:
>
>>  I'm not sure, that this code is correct?
>>
>>
>>
>> thx for help
>>
>>
>>
>> code:
>>
>> #include <stdio.h>
>>
>> #include <openssl/evp.h>
>>
>>
>>
>> int main(int argc, char *argv[])
>>
>> {
>>
>>                 unsigned char text[]="Hello World!";
>>
>>                 char key[]="password";
>>
>>                 char iv[]="12345678";
>>
>>
>>
>>                 unsigned char outbuf[1024];
>>
>>                 int outlen, tmplen, i;
>>
>>
>>
>>                 EVP_CIPHER_CTX ctx;
>>
>>                 EVP_CIPHER_CTX_init(&ctx);
>>
>>
>>
>>                 EVP_EncryptInit_ex(&ctx,EVP_aes_256_cbc(),NULL,key,iv);
>>
>>                 EVP_EncryptUpdate(&ctx,outbuf,&outlen,text,strlen(text));
>>
>>                 EVP_EncryptFinal_ex(&ctx,outbuf+outlen,&tmplen);
>>
>>                                outlen+=tmplen;
>>
>>                 EVP_CIPHER_CTX_cleanup(&ctx);
>>
>>
>>
>>                 printf("%s\n",outbuf);
>>
>>
>>
>>                 EVP_DecryptInit_ex(&ctx,EVP_aes_256_cbc(),NULL,key,iv);
>>
>>                 EVP_DecryptUpdate(&ctx,outbuf,&outlen,text,strlen(text));
>>
>>                 EVP_DecryptFinal_ex(&ctx,outbuf+outlen,&tmplen);
>>
>>                                outlen+=tmplen;
>>
>>                 EVP_CIPHER_CTX_cleanup(&ctx);
>>
>>
>>
>>                 printf("%s\n",text);
>>
>> }
>>
>
>

Reply via email to