AES Encryption with OpenSSL

Source: Internet
Author: User
Tags openssl api

Source:

#include <stdio.h>#include <memory.h>#include <stdlib.h>#include <openssl/aes.h>intMainintargcChar*argv[]) {unsigned Charbuf[ -] ="1234567890ABCDE";unsigned Charbuf2[ -];unsigned Charbuf3[ -];//key is 0    unsigned Charaes_keybuf[ +] = {0}; Aes_key Aeskey;//Set Encryption keyAes_set_encrypt_key (Aes_keybuf,8*sizeof(AES_KEYBUF), &aeskey);//EncryptionAes_encrypt (Buf,buf2,&aeskey);printf("%s\n", BUF2);//Set the decryption keyAes_set_decrypt_key (Aes_keybuf,8*sizeof(AES_KEYBUF), &aeskey);//DecryptionAes_decrypt (Buf2, BUF3, &aeskey);printf("%s\n", BUF3);return 0;}

OpenSSL API Description

intAes_set_encrypt_key (ConstUnsignedChar*userkey,Const intBitsAes_key*key);# #设置加密密钥# # UserKey for user-defined keys# # Bits key length# # Generated key (encrypted function will be used)intAes_set_decrypt_key (ConstUnsignedChar*userkey,Const intBitsAes_key*key);# #设置解密密钥# # UserKey for user-defined keys# # Bits key length# # Generated key (decryption function is used)//Cryptographic functionsvoidAes_encrypt (ConstUnsignedChar*in, unsignedChar*out,ConstAes_key*key);//Decryption functionvoidAes_decrypt (ConstUnsignedChar*in, unsignedChar*out,ConstAes_key*key);

Personal Summary:
The OpenSSL API probably uses steps to
Set encryption key –> encrypt data
Set decryption key –> decrypt data

About the key, can be customized;
It is also important to note that encryption and decryption of the data buffer must be a multiple of 16 (OpenSSL internal implementation, the data will be read in 16 char, again, the above program will only encrypt 16 bytes of data ...) Need to encrypt a longer string, the program can be modified under it)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

AES Encryption with OpenSSL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.