//
// Created by root on 24-4-17.
//
#include <cstring>
#include <openssl/aes.h>
#include <openssl/rand.h>
#include <iostream>

#ifndef RND_TEST_AES_CBC_IV_128_APPEND_H
#define RND_TEST_AES_CBC_IV_128_APPEND_H

#endif //RND_TEST_AES_CBC_IV_128_APPEND_H

#define BUFFER_SIZE 1024
#define AES_BLOCK_SIZE 16

void print_hex(const char *title, const unsigned char *s, int len);

int apply_pkcs7_padding(const unsigned char *input, int input_len, unsigned char *padded_input, int block_size);

int remove_pkcs7_padding(unsigned char *data, int input_len);

inline void iv_create(unsigned char *iv);

void iv_extract(unsigned char *iv, const unsigned char *encrypted, int encrypted_len);

void iv_append(unsigned char *iv, unsigned char *encrypted, int encrypted_len, unsigned char *output);

int aes_encrypt(const unsigned char *plaintext, int plaintext_len, const unsigned char *key, unsigned char *encrypted);

int aes_decrypt(const unsigned char *ciphertext, int ciphertext_len, const unsigned char *key, unsigned char *decrypted,
                int padded_plaintext_len);
