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

📄 dialog6.cpp

📁 别的的密钥管理程序
💻 CPP
字号:
// Dialog6.cpp : implementation file
//

#include "stdafx.h"
#include "bishe.h"
#include "Dialog6.h"
#include "BigInt.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialog6 dialog


CDialog6::CDialog6(CWnd* pParent /*=NULL*/)
	: CDialog(CDialog6::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialog6)
	//}}AFX_DATA_INIT
}


void CDialog6::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialog6)
	DDX_Control(pDX, IDC_MVIEW_LIST1, m_mview);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialog6, CDialog)
	//{{AFX_MSG_MAP(CDialog6)
	ON_BN_CLICKED(IDC_copy_BUTTON1, OncopyBUTTON1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialog6 message handlers


CString RSAEncode(char * m)//RSA加密算法
{
	CBigInt n, d, bm;
	CBigInt iRes;
	CString code;
	CString cm(m);

	bm.Get(cm);
	n.Get(g_KDCN);
	d.Get(g_KDCD);

	iRes = bm.RsaTrans(d,n);
	iRes.Put(code);

	return code;
}


BOOL CDialog6::OnInitDialog() 
{
	CDialog::OnInitDialog();

	m_mview.SetHorizontalExtent(2500);

	char pinfo[2048];
	char buffer[512];
	__int64 inf = 0;
	CString qm;
	unsigned int len;

	memset(pinfo, 0, 2048);
	// TODO: Add extra initialization here
	m_mview.AddString("版本:V3");//添加证书中的版本号
	
	strcpy(pinfo, "版本:V3");
	strcat(pinfo, "\n");
    //获取证书序列号(32位)
    srand((unsigned)time(NULL));

    unsigned short r1 =rand();
    unsigned short r2 =rand();

    DWORD r = (r1<<16) | r2;
    ZeroMemory(buffer,512);
	wsprintf(buffer, "%s%d","序列号:" ,r);
	CString serialNum((LPCSTR)buffer);
	strcat(pinfo,buffer);
	strcat(pinfo,"\n");

	m_mview.InsertString(1,serialNum); //添加证书中的序列号

    //获得用户名
	strcat(pinfo,"用户名: ");
	strcat(pinfo, g_USERNAME);
	strcat(pinfo, "\n");
    
	
    //签名算法和颁发者
	m_mview.InsertString(2,"签名算法:sha1RSA");//添加签名算法
	m_mview.InsertString(3,"颁发者:KDC");//添加颁发者

	strcat(pinfo,buffer);
	strcat(pinfo,"\n");
	strcat(pinfo,"签名算法:sha1RSA");
	strcat(pinfo,"\n");
	strcat(pinfo,"颁发者:KDC");
	strcat(pinfo,"\n");

	//获得证书有效期
	CTime tNow;
	tNow=CTime::GetCurrentTime();
	g_sTime=tNow.Format("%Y年%m月%d日%I时%M分%S秒");
	CString sTime=tNow.Format("有效期起始日期:%Y年%m月%d日%I时%M分%S秒");

	m_mview.InsertString(4,sTime);//添加有效期
	strcat(pinfo, sTime);
	strcat(pinfo,"\n");

	m_mview.InsertString(5,"有效期:1年");//添加有效期

	strcat(pinfo, "有效期:1年");
	strcat(pinfo, "\n");
    //获得公钥
    char sedit[512]="公钥: ";

	strcat(sedit,g_SE);

	m_mview.InsertString(6,sedit);//添加公钥

	strcat(pinfo, sedit);
	strcat(pinfo, "\n");

	//RSA签名
	len = strlen(pinfo);//已获得用户的信息存放在pinfo中
	int i,j;
	unsigned char tem[2048];
	for(i = 0; i < len; i++)
	{
		tem[i] = pinfo[i] > 0 ? pinfo[i] : (-pinfo[i]);
	}

	j = len%2;
	for(i = 0; i < len/2; i++)
		inf += ((tem[2*i]<<8) + tem[2*i + 1]);
	if(j == 1)
		inf += tem[2*i]<<8;		
	ZeroMemory(buffer,512);
	wsprintf(buffer, "%lx", inf);
	qm = RSAEncode(buffer);//签名
 
	ZeroMemory(buffer,512);
	wsprintf(buffer,"%s%s", "数字签名: ", qm);

	m_mview.InsertString(7,buffer);//添加数字签名


    
	memset(g_cerinfo, 0,2560);
	strcpy(g_cerinfo, pinfo);
	strcat(g_cerinfo,buffer);
	len = strlen(g_cerinfo);
	g_cerinfo[len] = '\0';

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDialog6::OncopyBUTTON1() 
{
	// TODO: Add your control notification handler code here
	CCeroutguide m_outguide;
	m_outguide.DoModal();
    
}

⌨️ 快捷键说明

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