AES.cpp 1.54 KB
#include "dll.h"
#include "cryptlib.h"
#include "aes.h"
#include "filters.h"
#include "md5.h"
#include "ripemd.h"
#include "rng.h"
#include "gzip.h"
#include "default.h"
#include "randpool.h"
#include "ida.h"
#include "base64.h"
#include "factory.h"
#include "whrlpool.h"
#include "tiger.h"
#include "smartptr.h"
#include "pkcspad.h"
#include "stdcpp.h"
#include "osrng.h"
#include "ossig.h"
#include "trap.h"

#include "validate.h"
#include "bench.h"

#include <iostream>
#include <sstream>
#include <locale>
#include <ctime>
#include <iostream>

#include "CDLTools.h"

#pragma comment(lib, "cryptlib.lib")
using namespace CryptoPP;

DL_DLL_API int __stdcall AESDecode(unsigned char *in_data, int length, unsigned char *out_data)
{
	if (!in_data || length == 0 || !out_data)
	{
		return -1;
	}
	unsigned char *hex_data = new unsigned char[length / 2];
	unsigned char *plain_hex_data = new unsigned char[length / 2];
	memset(hex_data, 0, length / 2);
	memset(plain_hex_data, 0, length / 2);
	StringToHex(in_data, length, hex_data);

	unsigned char aesKey[] = {  0x41, 0x45, 0x41, 0x42, 0x43, 0x33, 0x46, 0x43, 0x43, 0x36, 0x34, 0x35, 0x43, 0x39, 0x44, 0x38 }; //密钥
	unsigned char xorBlock[CryptoPP::AES::BLOCKSIZE]; //必须设定为全零
	memset(xorBlock, 0, CryptoPP::AES::BLOCKSIZE); //置零

	//解密
	CryptoPP::AESDecryption aesDecryptor;
	aesDecryptor.SetKey(aesKey, CryptoPP::AES::DEFAULT_KEYLENGTH);
	aesDecryptor.ProcessAndXorBlock(hex_data, xorBlock, plain_hex_data);

	memcpy(out_data, plain_hex_data, length / 2);

	delete hex_data;
	delete plain_hex_data;
	return 0;
}