Code:
#include <stdio.h>
#include <gcrypt.h>
#include <assert.h>
int main()
{
gcry_cipher_hd_t handle;
gcry_error_t err = 0;
char * plain_text ;
char * out ;
char * deout ;
size_t size_of_plain = sizeof(char) * 6;
size_t size_of_crypt = sizeof(char) * 601;
plain_text = malloc (size_of_plain);
out = malloc (size_of_crypt);
deout = malloc (size_of_crypt);
assert(plain_text);
assert(out);
assert(deout);
strcpy(plain_text , "Secret");
gcry_check_version (NULL);
gcry_control( GCRYCTL_DISABLE_SECMEM_WARN );
gcry_control( GCRYCTL_INIT_SECMEM, 16384, 0 );
{
err = gcry_cipher_open (&handle, GCRY_CIPHER_ARCFOUR,GCRY_CIPHER_MODE_STREAM,0);
if (err)
{
fprintf (stderr, "Failure: %s/%s\n",
gcry_strsource (err),
gcry_strerror (err));
fprintf (stdout, "Failure: %s/%s\n",
gcry_strsource (err),
gcry_strerror (err));
}
err = gcry_cipher_setkey (handle, "This is really strange , i read the documentation i googled for two days and nothing , i can't encrypt && decrypt",128);
if (err)
{
fprintf (stderr, "Failure: %s/%s\n",
gcry_strsource (err),
gcry_strerror (err));
fprintf (stdout, "Failure: %s/%s\n",
gcry_strsource (err),
gcry_strerror (err));
}
}
err = gcry_cipher_encrypt (handle,
(unsigned char *)out, sizeof(out), (const unsigned char *)plain_text,sizeof plain_text);
if (err)
{
fprintf (stderr, "Failure: %s/%s\n",
gcry_strsource (err),
gcry_strerror (err));
fprintf (stdout, "Failure: %s/%s\n",
gcry_strsource (err),
gcry_strerror (err));
}
printf(" out :%s ||| plain text %s\n",out, plain_text);
err = gcry_cipher_encrypt (handle,
(unsigned char *)deout, sizeof deout, (const unsigned char *)out,sizeof out);
if (err)
{
fprintf (stderr, "Failure: %s/%s\n",
gcry_strsource (err),
gcry_strerror (err));
fprintf (stdout, "Failure: %s/%s\n",
gcry_strsource (err),
gcry_strerror (err));
}
printf("deout: %s ||| out: %s ||| plain text: %s\n",deout, out,plain_text);
free(plain_text);
free(out);
free(deout);
gcry_cipher_close(handle);
return 0;
}
i get the next output :