AES.cpp
1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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;
}