-
Notifications
You must be signed in to change notification settings - Fork 3
/
AES.h
55 lines (46 loc) · 1.5 KB
/
AES.h
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
//-----本文件为AES加密算法的数据定义部分-----
#pragma once
#include <string.h>
#include "head.h"
class AES
{
public:
AES(unsigned char* key);
virtual ~AES(){};
unsigned char* Cipher(unsigned char* input);
unsigned char* InvCipher(unsigned char* input);
void* Cipher(void* input, int length=0);
void* InvCipher(void* input, int length);
void Cipher(char *input, char *output);
void InvCipher(char *inut, char *output);
private:
unsigned char Sbox[256];
unsigned char InvSbox[256];
unsigned char w[11][4][4];
void KeyExpansion(unsigned char* key, unsigned char w[][4][4]);
unsigned char FFmul(unsigned char a, unsigned char b);
void SubBytes(unsigned char state[][4]);
void ShiftRows(unsigned char state[][4]);
void MixColumns(unsigned char state[][4]);
void AddRoundKey(unsigned char state[][4], unsigned char k[][4]);
void InvSubBytes(unsigned char state[][4]);
void InvShiftRows(unsigned char state[][4]);
void InvMixColumns(unsigned char state[][4]);
int ascillToValue(const char ch);
char valueToHexCh(const int value);
int getUCharLen(const unsigned char *uch);
int strToUChar(const char *ch, unsigned char *uch);
int ucharToStr(const unsigned char *uch, char *ch);
int ucharToHex(const unsigned char *uch, char *hex);
int hexToUChar(const char *hex, unsigned char *uch);
};
class AesHelper
{
public:
AesHelper(QString key);
~AesHelper();
QString aesEncrypt(QString mingwen);
QString aesUncrypt(QString miwen);
private:
AES *aes;
};