11 October 2012

encrypt/decrypt with openssl API -2

The symmetric cipher commands allow data to be encrypted or decrypted using various block and stream ciphers using keys based on passwords.

int AES_set_encrypt_key(const uchar *userKey, const int bits, 
    AES_KEY *key);

void AES_cbc_encrypt(const uchar *in, uchar *out, const ulong length, 
    const AES_KEY *key, uchar *ivec, const int enc);
# ./encrypt password1
cb3d7f690989f7237fd4485a582ac5b2fe98be8ebd6e37c50bb4bdd734a95631
# ./decrypt cb3d7f690989f7237fd4485a582ac5b2fe98be8ebd6e37c50bb4bdd734a95631
password1
download encrypt.c from here
download decrypt.c from here
# echo -n "password1" > plain.txt
# openssl enc -aes-256-cbc -nosalt -k "1234567890abcdef" -iv 0 -in plain.txt -out enc.txt
# hexdump -C enc.txt 
00000000  aa 3b 81 85 64 bf 6d b9  35 de 59 c3 36 41 0e f2  |.;..d.m.5.Y.6A..|
# openssl enc -d -aes-256-cbc -nosalt -k "1234567890abcdef" -iv 0 -in enc.txt
password1


Reference:
http://saju.net.in/blog/?p=36
http://stackoverflow.com/questions/9889492/how-to-do-encryption-using-aes-in-openssl
http://www.128bitstudios.com/2010/05/31/file-encryption-with-openssl/

1 comment:

  1. Usually I do not post on blogs, but I wish to say that this post really forced me to do so! Thanks, incredibly nice article.

    Pgp security

    ReplyDelete