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

📄 rsakey.h

📁 rsa算法的c++实现,该程序实现利用私钥解密
💻 H
字号:

#ifndef __RSAKEYH__
#define __RSAKEYH__             // rsakey.h is #included

#include "flintpp.h"
#include "ripemd.h"

#define BLOCKTYPE_SIGN 01
#define BLOCKTYPE_ENCR 02


typedef struct 
{
public:
    LINT pubexp, prvexp, mod, p, q, ep, eq, r;
    USHORT bitlen_mod;  // Binary length of modulus
    USHORT bytelen_mod; // Length of modulus in bytes
} KEYSTRUCT;


typedef struct 
{
public:
    LINT pubexp, mod;
    USHORT bitlen_mod;  // Binary length of modulus
    USHORT bytelen_mod; // Length of modulus in bytes
}PKEYSTRUCT;


class RSAkey
{
public:
    inline RSAkey (void) {};
    RSAkey (const int);
    RSAkey (const int, const LINT&, const LINT& = 1);
    RSAKey ( const KEYSTRUCT&);
    PKEYSTRUCT export_public (void) const;
    UCHAR* decrypt (const LINT&, int*);
    LINT sign (const UCHAR* const, const int);
    void purge (void);
    RSAkey& operator= (const RSAkey&);
    KEYSTRUCT keyvalue() {return key;};
    void copycreate(const KEYSTRUCT&);

    friend int operator== (const RSAkey&, const RSAkey&);
    friend int operator!= (const RSAkey&, const RSAkey&);
    friend fstream& operator<< (fstream&, const RSAkey&);
    friend fstream& operator>> (fstream&, RSAkey&);
	
 // Auxiliary functions
    int makekey (const int, const LINT& = 1);
    int testkey (void);
    LINT fastdecrypt (const LINT&);


 // private:
    KEYSTRUCT key;

   };


class RSApub
{
  public:
    inline RSApub (void) {};
    RSApub (const RSAkey&);
	RSApub (const PKEYSTRUCT&);
    LINT crypt (const UCHAR* const , const int);
    UCHAR* verify (  int*, const LINT&);
    void purge (void);
    RSApub& operator= (const RSApub&);

    friend int operator== (const RSApub&, const RSApub&);
    friend int operator!= (const RSApub&, const RSApub&);
    friend fstream& operator<< (fstream&, const RSApub&);
    friend fstream& operator>> (fstream&, RSApub&);
	PKEYSTRUCT keyvalue() {return pkey;};

  private:
    PKEYSTRUCT pkey;
};


///////////////////////////////////////////////////////////////////////////////
// Auxiliary functions external to RSA-classes

// Function for PKCS#1 formatting of encryption blocks
UCHAR* format_pkcs1 (const UCHAR*, const int, const UCHAR, const UCHAR*, const int);

// Parser for decrypted Encryption Block, PKCS#1-formatted
UCHAR* parse_pkcs1 (const UCHAR*, int*);

#endif // __RSAKEYH__







⌨️ 快捷键说明

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