#include<windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/aes.h>
#include<iostream>
using namespace std;
#pragma comment(lib,"libssl.lib")
#pragma comment(lib,"libcrypto.lib")
#define code1024 117
#define code512 53
char g_pPubFile[30] = { 0 };
char g_pPriFile[30] = { 0 };
//maxCodeByte = g_nBits/8-11这里设置了2048,意味着最多可以 编、解码 2048/8-11=117个字节
const int g_nBits = 1024;
using namespace std;
bool ReadTxt(unsigned char(&buf)[3200])
{
FILE *fp;
if ((fp = fopen("1.txt", "rb")) == NULL)
{
return false;
}
fseek(fp, 0, SEEK_END);
int fileLen = ftell(fp);
char *tmp = new char[fileLen];
fseek(fp, 0, SEEK_SET);
fread(tmp, fileLen, sizeof(char), fp);
fclose(fp);
memcpy(buf, tmp, fileLen);
delete tmp;
return true;
}
bool WriteTxt(unsigned char(&Decbuf)[3200])
{
FILE *fp;
if ((fp = fopen("2.txt", "wb")) == NULL)
{
return false;
}
rewind(fp);
int fileLen = strlen((char*)Decbuf);
fwrite(Decbuf, fileLen, sizeof(char), fp);
fclose(fp);
}
RSA功能函数部分///
//************************************
// function: 产生公私钥对,并保存为pem格式的文件。用来后续的加密解密
利用openssl的AES加密解密数据明文(ECB模式)
最新推荐文章于 2025-04-11 15:35:01 发布