Hi OpenSSL Team,

I am Anil, trying to code aes encryption and decryption program using
openssl library.

I have coded a program which takes key and data as inputs and computes
AES-128 cipher text and decrypt the same. *If the size of the data/Key
changes, size of cipher text is also getting changed .Is it expected
behavior ?*
*
*
Here is my code:

#include <stdio.h>
#include <openssl/aes.h>
main()
{
     unsigned char text[1024];
     unsigned char out[1024];
     unsigned char decout[1024];
     int i;
     char key[17];



      AES_KEY ectx;
      AES_KEY dectx;
      memset(out, '\0', sizeof(out));
      memset(decout, '\0', sizeof(decout));

      printf("Enter the text:");
      scanf("%s", text);

      printf("AES Key:");
      scanf("%s", key);


      AES_set_encrypt_key(key, 128, &ectx);
      AES_encrypt(text, out, &ectx);

      //out[16] = '\0';
      printf("Length of encrypted data: %d\n", strlen(out));


      printf("encryp data = %s\n", out);

      AES_set_decrypt_key(key, 128, &dectx);
      AES_decrypt(out, decout, &dectx);
      //decout[16] = '\0';

      printf(" Decrypted o/p: %s \n", decout);

      for (i = 0;i < 16; i++)
          printf(" %02x", decout[i]);
      printf("\n");
  }



Please correct me if I have gone wrong anywhere ?

Thanks
-Anil

Reply via email to