aesinterface.h

来自「这是一个简单的AES加密解密的程序」· C头文件 代码 · 共 39 行

H
39
字号


struct IAesInterface
{
	//Operation Modes
	//The Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback Block (CFB) modes
	//are implemented.
	//In ECB mode if the same block is encrypted twice with the same key, the resulting
	//ciphertext blocks are the same.
	//In CBC Mode a ciphertext block is obtained by first xoring the
	//plaintext block with the previous ciphertext block, and encrypting the resulting value.
	//In CFB mode a ciphertext block is obtained by encrypting the previous ciphertext block
	//and xoring the resulting value with the plaintext.
	enum { ECB=0, CBC=1, CFB=2 };
	enum { DEFAULT_BLOCK_SIZE=16 };
	enum { MAX_BLOCK_SIZE=32, MAX_ROUNDS=14, MAX_KC=8, MAX_BC=8 };

	virtual void MakeKey(char const* key, int keylength=DEFAULT_BLOCK_SIZE, int blockSize=DEFAULT_BLOCK_SIZE) = 0;
	//Encrypt exactly one block of plaintext.
	// in           - The plaintext.
    // result       - The ciphertext generated from a plaintext using the key.
    virtual void EncryptBlock(char const* in, char* result) = 0;
	
	//Decrypt exactly one block of ciphertext.
	// in         - The ciphertext.
	// result     - The plaintext generated from a ciphertext using the session key.
	virtual void DecryptBlock(char const* in, char* result) = 0;

	virtual void Encrypt(char const* in, char* result, size_t n, int iMode=ECB) = 0;
	
	virtual void Decrypt(char const* in, char* result, size_t n, int iMode=ECB) = 0;
};


//创建一个Aes实例
extern IAesInterface* CreateAesInstance();
//释放一个Aes实例
extern void DestroyAesInstance(IAesInterface* _aes);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?