AES加密解密

AES简介:

高级加密标准为最常见的对称加密算法。对称加密算法也就是加密和解密用相同的密钥。

AES加密方式有五种:ECB、CBC、CTR、CFB、OFB

CBC:加密需要一个十六位的key密钥和一个十六位iv偏移量

ECB:加密不需要iv


AES在线加解密:在线AES加密解密、AES在线加密解密、AES encryption and decryption--查错网


如下为采用ECB加密模式、pkcs7填充、128位数据块、base64编码

实现代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/aes.h>
#include <openssl/rand.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <errno.h>

char SESSION_KEY[128] = "1234567890123456";

void handleOpenSSLErrors(void)
{
    unsigned long errCode;
    errCode = 0;

    printf("An error occurred\n");
    while(errCode == ERR_get_error()) {
        char *err = ERR_error_string(errCode, NULL);
        printf("%s\n", err);
    }
    //abort();
}

char * base64Encode(const char *buffer, int length, int newLine)
{
    BIO *bmem = NULL;
    BIO *b64 = NULL;
    BUF_MEM *bptr;

    b64 = BIO_new(BIO_f_base64());
    if (!newLine) {
        BIO_set_flags(b64, BIO_FLAGS_BASE64_NO
  • 7
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不会C语言的男孩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值