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

📄 rsawapper.h

📁 基于SD卡的软实现CSP程序
💻 H
字号:
#pragma once
#include <iostream>
#include <string>
#include <memory>

typedef unsigned char       BYTE;

class RSAImpl;
class RSAWapper
{
public:
	RSAWapper(const int RSAPubKeyLength_InBit=1024);
	~RSAWapper(void);

	//Generate new keys.
	void GenerateKeys();

	//if you want to set both pri & pub keys, you SHOULD set pub keys first!!
	//the BYTE stream number SHOUD BE this order: High byte in number--[0]>[1]>[2]>[3]>....--low byte in number.
	//That means p[4]={0x12,0x34,0x56,0x78} stands for number: 0x12345678.
	void setPriKeys(const BYTE* pBuf,const size_t pBufLen,const BYTE* qBuf,const size_t qBufLen);	
	void setPubKeys(const int e,const BYTE* nBuf,const size_t nBufLen);
	void getPubKeys(int& e,BYTE* nBuf,const size_t nBufLen) const;
	void getPriKeys(BYTE* pBuf,const size_t pBufLen,BYTE* qBuf,const size_t qBufLen) const;	
	
	//Load all keys that we want and can find.
	//If you give file name like "Jim", we will find "Jim.Pub" for Pub keys and 
	//(if LoadPriKeyAlso is true) find "Jim.Pri" for Pri keys.
	//If we load all wanted keys, return true.
	//else return false.
	bool LoadKeys(const std::string& keyFileName, bool LoadPriKeyAlso=false);
	void SaveKeys(const std::string& keyFileName, bool SavePriKeyAlso=false) const;

	//only for mobile, to init faster.
	bool LoadKeysforMobile(const std::string& keyFileName);
	void SaveKeysforMobile(const std::string& keyFileName);
	
	//inLen SHOULD be smaller than PubKeyLength-2!
	//or it will throw.
	void Encrypt(const BYTE* inBuf,const size_t inLen,BYTE* outBuf,const size_t outBufLen) const;	
	
	//length of inBuf SHOULD be larger than PubKeyLength in Byte!
	size_t Decrypt(const BYTE* inBuf,BYTE* outBuf,const size_t outBufLen) const;
	
	//Auto chose sign padding mode.
	//Now we implemented two mode: Raw and PKCS1.5.
	//Raw mode requires inLen to smaller than  PubKeyLength_inByte -2
	//And PKCS1.5 mode requires inLen to smaller than  PubKeyLength_inByte -11
	void Sign(const BYTE* inBuf,const size_t inLen,BYTE* outBuf,const size_t outBufLen) const;
	
	//length of inBuf SHOULD be larger than PubKeyLength in Byte!
	size_t Authen(const BYTE* inBuf,BYTE* outBuf,const size_t outBufLen) const;	
private:
	std::auto_ptr<RSAImpl> myKeys;
	RSAWapper (const RSAWapper& rhs);
	RSAWapper operator=(const RSAWapper& rhs);
};

⌨️ 快捷键说明

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