?? rsawapper.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 + -