Advertisement
KekSec

aes.c

Feb 25th, 2016
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. #include <openssl/aes.h>
  2. #include <stdio.h>
  3.  
  4. //AES ENCRYPTION KEY (CHANGE THIS)
  5. static const unsigned char key[] = {
  6.     0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
  7.     0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
  8.     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  9.     0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
  10. };
  11.  
  12. int main(int argc, char *argv[]) {
  13.  
  14.     AES_KEY enc_key, dec_key;
  15.     unsigned char enc_out[1024];
  16.     unsigned char dec_out[1024];
  17.  
  18.     if (strcmp(argv[2], "1") == 0)
  19.     {
  20.         AES_set_encrypt_key(key, 256, &enc_key);
  21.         int len = strlen(argv[1]); //or get cipher text length by any mean.
  22.         int i;
  23.         for(i=0; i<=len; i+=16)
  24.             AES_encrypt(argv[1]+i, enc_out+i, &enc_key);
  25.         //AES_encrypt(argv[1], enc_out, &enc_key);    
  26.         puts(enc_out);
  27.         return 0;
  28.     } else {
  29.         AES_set_decrypt_key(key, 256,&dec_key);
  30.         int len = strlen(argv[1]); //or get cipher text length by any mean.
  31.         int i;
  32.         for(i=0; i<=len; i+=16)
  33.             AES_decrypt(argv[1]+i, dec_out+i, &dec_key);
  34.         //AES_decrypt(argv[1], dec_out, &dec_key);
  35.         puts(dec_out);
  36.         return 0;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement