void aes_encrypt(uint8_t *key, uint8_t *in, uint8_t *out)的示例代码,不使用openssl
时间: 2023-12-01 09:41:05 浏览: 86
以下是一个使用AES加密算法的示例代码,不使用openssl:
```c
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "aes.h"
void aes_encrypt(uint8_t *key, uint8_t *in, uint8_t *out) {
struct AES_ctx ctx;
uint8_t iv[AES_BLOCKLEN] = {0};
AES_init_ctx_iv(&ctx, key, iv);
AES_ECB_encrypt(&ctx, in, out);
}
int main() {
uint8_t key[AES_KEYLEN] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
uint8_t in[AES_BLOCKLEN] = {0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34};
uint8_t out[AES_BLOCKLEN];
aes_encrypt(key, in, out);
printf("Encrypted: ");
for (int i = 0; i < AES_BLOCKLEN; i++) {
printf("%02x", out[i]);
}
printf("\n");
return 0;
}
```
阅读全文