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

📄 rsa.h

📁 详细的AESRSASHA1实现原理
💻 H
字号:
// RSA.h: interface for the CRSA class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_RSA_H__8A78E737_548F_40E7_8064_24A6FDEA188F__INCLUDED_)
#define AFX_RSA_H__8A78E737_548F_40E7_8064_24A6FDEA188F__INCLUDED_

//////////////////////////////////////////////////////////////////////
// m--message; c--cryptgraph; p,q--large prime; n=p*q; f=(p-1)*(q-1)
// given e=65537 select d ensure that e*d%f=1 ==>e*d=x*f+1
//
// send: encrypt M using e, and get c=pow(m,e)%n;
// recieve: decrypt C using d, 
//          text=pow(c,d)%n=pow(m,e*d)%n=pow(m,x*f+1)%n=pow(m,1)%n=m
//////////////////////////////////////////////////////////////////////

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "Huge.h"

//////////////////////////////////////////////////////////////////////
// typedef / constant
//////////////////////////////////////////////////////////////////////
#define MAX_RSA_BLOCKS  2000

const unsigned RSA_BLOCK_BYTE_SIZE = 16;
const unsigned RSA_BLOCK_BIT_SIZE  = RSA_BLOCK_BYTE_SIZE<<3;

typedef BYTE RSA_BLOCK[RSA_BLOCK_BYTE_SIZE+1];

//////////////////////////////////////////////////////////////////////
// Class CRSA
//////////////////////////////////////////////////////////////////////
class CRSA
{
public:
    CRSA();
    virtual ~CRSA();
    
private:
    CHuge       m_cP, m_cQ;
    CHuge	    m_cE, m_cD;
    CHuge	    m_cN, m_cFN;

    int		    m_iBlocks;
    RSA_BLOCK	m_pBlocks[MAX_RSA_BLOCKS];
    bool        m_bInitial;
    
public:  
    void    Initial( );
    bool    GetInitial( );
    void    GetKeyN( CString& strKey );

    void    Encrypt( CString strMsg, CString& strCrypt );
    void    Decrypt( CString strCrypt, CString& strDecrypt ); 

private:
    void    TransMsgToBlocks( CString strMsg );
    void    TransBlocksToCryptInHex( CString& strCrypt );
    void    TransBlocksToDecrypt( CString& strDecrypt );

    void    EncryptBlock( RSA_BLOCK b );
    void    DecryptBlock( RSA_BLOCK b );
};

#endif // !defined(AFX_RSA_H__8A78E737_548F_40E7_8064_24A6FDEA188F__INCLUDED_)

⌨️ 快捷键说明

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