#include <stdio.h>
#include <string.h>
#include <openssl/x509.h>
#include <openssl/evp.h>
#include <openssl/err.h>
int main()
{
EVP_CIPHER_CTX ctx;
X509_ALGOR *alg;
unsigned char* passwd = "password";
unsigned char *message = "Test message";
int bytes_enc, bytes_final, bytes_dec, err;
unsigned char *dec_buff = NULL, *enc_buff = NULL;
alg = PKCS5_pbe2_set (EVP_des_cbc(), -1, NULL, 0);
if (alg == NULL)
{
ERR_print_errors_fp (stderr);
exit(1);
}
err = EVP_PBE_CipherInit (alg->algorithm, passwd, strlen(passwd), alg->parameter, &ctx, 1);
if ( err == 0 )
{
ERR_print_errors_fp(stderr);
exit(1);
}
enc_buff = (unsigned char *) malloc (strlen(message) + EVP_CIPHER_CTX_block_size(&ctx) - 1);
err = EVP_CipherUpdate (&ctx, enc_buff, &bytes_enc, message, strlen(message));
if ( err == 0 )
{
ERR_print_errors_fp(stderr);
exit(1);
}
err = EVP_CipherFinal (&ctx, enc_buff + bytes_enc, &bytes_final);
if ( err = 0 )
{
ERR_print_errors_fp (stderr);
exit(1);
}
bytes_enc += bytes_final;
printf("%s",bytes_enc);
//int i;
//scanf("%d",&i);
EVP_PBE_CipherInit (alg->algorithm, passwd, strlen(passwd), alg->parameter, &ctx, 0);
dec_buff = (unsigned char *) malloc (bytes_enc + EVP_CIPHER_CTX_block_size(&ctx) + 1);
EVP_CipherUpdate (&ctx, dec_buff, &bytes_dec, enc_buff, bytes_enc);
EVP_CipherFinal (&ctx, dec_buff + bytes_dec, &bytes_final);
bytes_dec += bytes_final;
dec_buff[bytes_dec] = '\0';
printf("Original message is: %s\n", message);
printf("Recovered message is: %s\n", dec_buff);
return 1;
}
But i am getting the following error:
1536:error:06074079:lib(6):func(116):reason(121):evp_pbe.c:89:TYPE=PBES2
Any suggestions?
Thanks,
Joe
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.