Where is simple example of crypt string with AES?



________
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/err.h>

int main(int argc, char **argv) {

        BIO *benc, *bin, *bout;
        EVP_CIPHER *type;
        HMAC_CTX hctx;
        unsigned char buf[128];
        unsigned char key[24];
        unsigned char iv[SHA_DIGEST_LENGTH];
        unsigned char salt[PKCS5_SALT_LEN];

       ERR_load_crypto_strings();

        RAND_pseudo_bytes(salt, sizeof(salt));
        benc = BIO_new(BIO_f_cipher());
        type = EVP_aes_256_cbc();
        EVP_BytesToKey(type, EVP_sha1(), salt, pin, strlen(pin), 1, key,
iv);

        BIO_set_cipher(benc, type, key, iv, mode);
        bout = BIO_push(benc, bout);
        HMAC_Init(&hctx, key, sizeof(key), EVP_sha1());
        HMAC_Update(&hctx, buf, inl);
        HMAC_Final(&hctx, hmd, &hmd_len);
        HMAC_cleanup(&hctx);
        EVP_cleanup();

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to