⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encoderimplbase.h

📁 这是一个基于VS2003开发的数据加密和解密的程序
💻 H
字号:
/*!
	\file EncoderImplBase.h
	\author Jackson
	\date 13/1/2005
*/

#ifndef _LUCID_ENCRYPTION_ENCODERIMPLBASE_H_
#define _LUCID_ENCRYPTION_ENCODERIMPLBASE_H_

#ifdef _MSC_VER
#	include <mbstring.h>
#endif

#include "ShareLib.h"

#include <string.h>
#include "EncodeAlgorithm.h"

namespace Lucid {

namespace Encryption {

//! \class TEncoderImplBase
/*!
	\brief Encoder implementation interface
*/
class TEncoderImplBase {
public:
	enum {
		MAX_KEY_LEN = 16,
		MAX_IV_LEN = 16
	};

	//! Constructor
	/*!
		\param key key for encryption
		\param key_length length of key
		\param iv initial vector encryption
		\param iv_length length of initial vector
		\param algorithm encode algorithm used
	*/
	TEncoderImplBase(const unsigned char* key, unsigned int key_length, const unsigned char* iv = 0, unsigned int iv_length = 0, TEncodeAlgorithm algorithm = NO_ENCODE) : mKeyLength(key_length), mIVLength(iv_length), mAlgorithm(algorithm) {
#ifdef _MSC_VER
		_mbsncpy(mKey, key, key_length);
#else
		strncpy((char*)mKey, (char*)key, key_length);
#endif
		if (iv) {
#ifdef _MSC_VER
			_mbsncpy(mIV, iv, iv_length);
#else
			strncpy((char*)mIV, (char*)iv, iv_length);
#endif
		}
	}

	//! Desstructor
	/*!
	*/
	virtual ~TEncoderImplBase() {}

	/*!
		\brief encode input byte array
		\param input input byte array
		\param output output byte array
		\param input_len length of input array
		\param output_len length of output array
	*/
	virtual void Encode(const unsigned char* input, unsigned char* output, const int input_len, int& output_len) = 0;

	/*!
		\brief decode input byte array
		\param input input byte array
		\param output output byte array
		\param input_len length of input array
		\param output_len length of output array
	*/
	virtual void Decode(const unsigned char* input, unsigned char* output, const int input_len, int& output_len) = 0;

	/*!
		\brief get the key for encryption/ decryption
	*/
	const unsigned char* GetKey() const {
		return mKey;
	}

	/*!
		\brief get the key length for encryption/ decryption
	*/
	unsigned int GetKeyLength() const {
		return mKeyLength;
	}

	/*!
		\brief get the initial vector for encryption/ decryption
	*/
	const unsigned char* GetIV() const {
		return mIV;
	}

	/*!
		\brief get the initial vector length for encryption/ decryption
	*/
	unsigned int GetIVLength() const {
		return mIVLength;
	}

	/*!
		\brief get the algorithm for encryption/ decryption
	*/
	TEncodeAlgorithm GetAlgorithm() const {
		return mAlgorithm;
	}

private:
	unsigned char mKey[MAX_KEY_LEN];
	unsigned char mIV[MAX_IV_LEN];
	unsigned int mKeyLength;
	unsigned int mIVLength;
	TEncodeAlgorithm mAlgorithm;
};

}

}

#endif	// _LUCID_ENCRYPTION_ENCODERIMPLBASE_H_

⌨️ 快捷键说明

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