Created
May 3, 2016 21:45
-
-
Save xfbs/3e84f90b9cae858400de377a75ef28cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <stdbool.h> | |
| #include <openssl/evp.h> | |
| #include <openssl/err.h> | |
| #include <openssl/rand.h> | |
| #include <openssl/engine.h> | |
| int main(int argc, char *argv[]) { | |
| EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); | |
| const EVP_CIPHER *cipher = EVP_aes_128_ecb(); | |
| int keylen = 16; | |
| int blocksize = 16; | |
| int encrypt = 1; | |
| int padding = false; | |
| EVP_CIPHER_CTX_set_padding(ctx, padding); | |
| const unsigned char key[16] = {0x12,0x34,0x56,0x78,0x90,0xAB,0xCD,0xEF}; | |
| EVP_CipherInit(ctx, cipher, key, NULL, encrypt); | |
| const unsigned char plaintext[16] = "YELLOW SUBMARINE"; | |
| unsigned char buffer[64]; | |
| int buffer_size = 0; | |
| int buffer_size_inc = 16; | |
| EVP_CipherUpdate(ctx, | |
| buffer, | |
| &buffer_size_inc, | |
| plaintext, | |
| 16); | |
| buffer_size += buffer_size_inc; | |
| buffer_size_inc = 64; | |
| EVP_CipherFinal(ctx, | |
| buffer, | |
| &buffer_size_inc); | |
| printf("buffer size: %i\n", buffer_size); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment