aes解码和base64解码 c++代码
时间: 2023-11-09 21:06:30 浏览: 161
base64编码和解码c++代码
AES解码和Base64解码是两种不同的编码方式。AES是一种对称加密算法,用于加密和解密数据,而Base64是一种编码方式,用于将二进制数据转换为可打印字符。以下是C++代码示例:
AES解码:
```c++
#include <iostream>
#include <openssl/aes.h>
int main()
{
unsigned char key[] = "01234567890123456789012345678901";
unsigned char iv[] = "0123456789012345";
unsigned char ciphertext[] = "ciphertext";
unsigned char decryptedtext[128];
AES_KEY aesKey;
AES_set_decrypt_key(key, 256, &aesKey);
AES_cbc_encrypt(ciphertext, decryptedtext, sizeof(ciphertext), &aesKey, iv, AES_DECRYPT);
std::cout << decryptedtext << std::endl;
return 0;
}
```
Base64解码:
```c++
#include <iostream>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/buffer.h>
int main()
{
std::string encodedText = "SGVsbG8gV29ybGQh";
BIO *bio, *b64;
b64 = BIO_new(BIO_f_base64()); bio = BIO_new_mem_buf(encodedText.c_str(), -1);
bio = BIO_push(b64, bio);
char decodedText[128];
int len = BIO_read(bio, decodedText, sizeof(decodedText));
BIO_free_all(bio);
std::cout << std::string(decodedText, len) << std::endl;
return 0;
}
```
阅读全文