国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

RSA加密解密及RSA簽名和驗證

2024-07-21 02:24:32
字體:
來源:轉載
供稿:網友
注冊會員,創建你的web開發資料庫,此demo包含兩個文件,建立一個解決方案,然后建立兩個文件,一個為form,一個為class,把代碼分別復制進去即可

rsa正確的執行過程:
加密解密:
1、獲取密鑰,這里是產生密鑰,實際應用中可以從各種存儲介質上讀取密鑰
2、加密
3、解密
簽名和驗證:
簽名:
1、獲取密鑰,這里是產生密鑰,實際應用中可以從各種存儲介質上讀取密鑰
2、獲取待簽名的hash碼
3、簽名
其中,1和2的步驟無所謂,在本例中,我們將對txtsource里的內容進行簽名,也可以對文件進行簽名
驗證簽名:
1、獲取密鑰,這里是產生密鑰,實際應用中可以從各種存儲介質上讀取密鑰
2、獲取待驗證簽名的hash碼
3、獲取簽名的字串,這里簽名的字串存儲在m_strencryptedsignaturedata變量中,在demo中必須通過簽名才能獲得這個字串,因此需要先執行簽名,當然也可以更改之后通過別的方式獲得
4、驗證
其中,1和2的步驟無所謂,在本例中,我們將對txtsource里的內容進行簽名驗證,也可以對文件進行簽名驗證
如果是文件,取得文件之后把文件的內容以byte[]的方式代入即可
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//rsacryption.cs
///////////////////////////////////////////////////////////////////////////////////////////////////////////
using system;
using system.text;
using system.security.cryptography;

namespace rsaapplication
{
/// <summary>
/// rsacryption 的摘要說明。
/// </summary>
public class rsacryption
{
#region 構造函數

public rsacryption()
{
//
// todo: 在此處添加構造函數邏輯
//
}
#endregion

#region rsa 加密解密

#region rsa 的密鑰產生
//rsa 的密鑰產生
//產生私鑰 和公鑰
public void rsakey(out string xmlkeys,out string xmlpublickey)
{
try
{
system.security.cryptography.rsacryptoserviceprovider rsa=new rsacryptoserviceprovider();
xmlkeys=rsa.toxmlstring(true);
xmlpublickey = rsa.toxmlstring(false);
}
catch(exception ex)
{
throw ex;
}
}
#endregion
#region rsa的加密函數
//##############################################################################
//rsa 方式加密
//說明key必須是xml的行式,返回的是字符串
//在有一點需要說明!!該加密方式有 長度 限制的!!
//##############################################################################

//rsa的加密函數
public string rsaencrypt(string xmlpublickey,string m_strencryptstring )
{
try
{
byte[] plaintextbarray;
byte[] cyphertextbarray;
string result;
system.security.cryptography.rsacryptoserviceprovider rsa=new rsacryptoserviceprovider();
rsa.fromxmlstring(xmlpublickey);
plaintextbarray = (new unicodeencoding()).getbytes(m_strencryptstring);
cyphertextbarray = rsa.encrypt(plaintextbarray, false);
result=convert.tobase64string(cyphertextbarray);
return result;
}
catch(exception ex)
{
throw ex;
}
}
//rsa的加密函數
public string rsaencrypt(string xmlpublickey,byte[] encryptstring )
{
try
{
byte[] cyphertextbarray;
string result;
system.security.cryptography.rsacryptoserviceprovider rsa=new rsacryptoserviceprovider();
rsa.fromxmlstring(xmlpublickey);
cyphertextbarray = rsa.encrypt(encryptstring, false);
result=convert.tobase64string(cyphertextbarray);
return result;
}
catch(exception ex)
{
throw ex;
}
}
#endregion

#region rsa的解密函數
//rsa的解密函數
public string rsadecrypt(string xmlprivatekey, string m_strdecryptstring )
{
try
{
byte[] plaintextbarray;
byte[] dyphertextbarray;
string result;
system.security.cryptography.rsacryptoserviceprovider rsa=new rsacryptoserviceprovider();
rsa.fromxmlstring(xmlprivatekey);
plaintextbarray =convert.frombase64string(m_strdecryptstring);
dyphertextbarray=rsa.decrypt(plaintextbarray, false);
result=(new unicodeencoding()).getstring(dyphertextbarray);
return result;
}
catch(exception ex)
{
throw ex;
}
}

//rsa的解密函數
public string rsadecrypt(string xmlprivatekey, byte[] decryptstring )
{
try
{
byte[] dyphertextbarray;
string result;
system.security.cryptography.rsacryptoserviceprovider rsa=new rsacryptoserviceprovider();
rsa.fromxmlstring(xmlprivatekey);
dyphertextbarray=rsa.decrypt(decryptstring, false);
result=(new unicodeencoding()).getstring(dyphertextbarray);
return result;
}
catch(exception ex)
{
throw ex;
}
}
#endregion

#endregion

#region rsa數字簽名

#region 獲取hash描述表
//獲取hash描述表
public bool gethash(string m_strsource, ref byte[] hashdata)
{
try
{
//從字符串中取得hash描述
byte[] buffer;
system.security.cryptography.hashalgorithm md5 = system.security.cryptography.hashalgorithm.create("md5");
buffer = system.text.encoding.getencoding("gb2312").getbytes(m_strsource);
hashdata = md5.computehash(buffer);

return true;
}
catch(exception ex)
{
throw ex;
}
}

//獲取hash描述表
public bool gethash(string m_strsource, ref string strhashdata)
{
try
{
//從字符串中取得hash描述
byte[] buffer;
byte[] hashdata;
system.security.cryptography.hashalgorithm md5 = system.security.cryptography.hashalgorithm.create("md5");
buffer = system.text.encoding.getencoding("gb2312").getbytes(m_strsource);
hashdata = md5.computehash(buffer);

strhashdata = convert.tobase64string(hashdata);
return true;
}
catch(exception ex)
{
throw ex;
}
}

//獲取hash描述表
public bool gethash(system.io.filestream objfile, ref byte[] hashdata)
{
try
{
//從文件中取得hash描述
system.security.cryptography.hashalgorithm md5 = system.security.cryptography.hashalgorithm.create("md5");
hashdata = md5.computehash(objfile);
objfile.close();

return true;
}
catch(exception ex)
{
throw ex;
}
}

//獲取hash描述表
public bool gethash(system.io.filestream objfile, ref string strhashdata)
{
try
{
//從文件中取得hash描述
byte[] hashdata;
system.security.cryptography.hashalgorithm md5 = system.security.cryptography.hashalgorithm.create("md5");
hashdata = md5.computehash(objfile);
objfile.close();

strhashdata = convert.tobase64string(hashdata);

return true;
}
catch(exception ex)
{
throw ex;
}
}
#endregion

#region rsa簽名
//rsa簽名
public bool signatureformatter(string p_strkeyprivate, byte[] hashbytesignature, ref byte[] encryptedsignaturedata)
{
try
{
system.security.cryptography.rsacryptoserviceprovider rsa = new system.security.cryptography.rsacryptoserviceprovider();

rsa.fromxmlstring(p_strkeyprivate);
system.security.cryptography.rsapkcs1signatureformatter rsaformatter = new system.security.cryptography.rsapkcs1signatureformatter(rsa);
//設置簽名的算法為md5
rsaformatter.sethashalgorithm("md5");
//執行簽名
encryptedsignaturedata = rsaformatter.createsignature(hashbytesignature);

return true;
}
catch(exception ex)
{
throw ex;
}
}

//rsa簽名
public bool signatureformatter(string p_strkeyprivate, byte[] hashbytesignature, ref string m_strencryptedsignaturedata)
{
try
{
byte[] encryptedsignaturedata;

system.security.cryptography.rsacryptoserviceprovider rsa = new system.security.cryptography.rsacryptoserviceprovider();

rsa.fromxmlstring(p_strkeyprivate);
system.security.cryptography.rsapkcs1signatureformatter rsaformatter = new system.security.cryptography.rsapkcs1signatureformatter(rsa);
//設置簽名的算法為md5
rsaformatter.sethashalgorithm("md5");
//執行簽名
encryptedsignaturedata = rsaformatter.createsignature(hashbytesignature);

m_strencryptedsignaturedata = convert.tobase64string(encryptedsignaturedata);

return true;
}
catch(exception ex)
{
throw ex;
}
}

//rsa簽名
public bool signatureformatter(string p_strkeyprivate, string m_strhashbytesignature, ref byte[] encryptedsignaturedata)
{
try
{
byte[] hashbytesignature;

hashbytesignature = convert.frombase64string(m_strhashbytesignature);
system.security.cryptography.rsacryptoserviceprovider rsa = new system.security.cryptography.rsacryptoserviceprovider();

rsa.fromxmlstring(p_strkeyprivate);
system.security.cryptography.rsapkcs1signatureformatter rsaformatter = new system.security.cryptography.rsapkcs1signatureformatter(rsa);
//設置簽名的算法為md5
rsaformatter.sethashalgorithm("md5");
//執行簽名
encryptedsignaturedata = rsaformatter.createsignature(hashbytesignature);

return true;
}
catch(exception ex)
{
throw ex;
}
}

//rsa簽名
public bool signatureformatter(string p_strkeyprivate, string m_strhashbytesignature, ref string m_strencryptedsignaturedata)
{
try
{
byte[] hashbytesignature;
byte[] encryptedsignaturedata;

hashbytesignature = convert.frombase64string(m_strhashbytesignature);
system.security.cryptography.rsacryptoserviceprovider rsa = new system.security.cryptography.rsacryptoserviceprovider();

rsa.fromxmlstring(p_strkeyprivate);
system.security.cryptography.rsapkcs1signatureformatter rsaformatter = new system.security.cryptography.rsapkcs1signatureformatter(rsa);
//設置簽名的算法為md5
rsaformatter.sethashalgorithm("md5");
//執行簽名
encryptedsignaturedata = rsaformatter.createsignature(hashbytesignature);

m_strencryptedsignaturedata = convert.tobase64string(encryptedsignaturedata);

return true;
}
catch(exception ex)
{
throw ex;
}
}
#endregion

#region rsa 簽名驗證

public bool signaturedeformatter(string p_strkeypublic, byte[] hashbytedeformatter, byte[] deformatterdata)
{
try
{
system.security.cryptography.rsacryptoserviceprovider rsa = new system.security.cryptography.rsacryptoserviceprovider();

rsa.fromxmlstring(p_strkeypublic);
system.security.cryptography.rsapkcs1signaturedeformatter rsadeformatter = new system.security.cryptography.rsapkcs1signaturedeformatter(rsa);
//指定解密的時候hash算法為md5
rsadeformatter.sethashalgorithm("md5");

if(rsadeformatter.verifysignature(hashbytedeformatter,deformatterdata))
{
return true;
}
else
{
return false;
}
}
catch(exception ex)
{
throw ex;
}
}

public bool signaturedeformatter(string p_strkeypublic, string p_strhashbytedeformatter, byte[] deformatterdata)
{
try
{
byte[] hashbytedeformatter;

hashbytedeformatter = convert.frombase64string(p_strhashbytedeformatter);

system.security.cryptography.rsacryptoserviceprovider rsa = new system.security.cryptography.rsacryptoserviceprovider();

rsa.fromxmlstring(p_strkeypublic);
system.security.cryptography.rsapkcs1signaturedeformatter rsadeformatter = new system.security.cryptography.rsapkcs1signaturedeformatter(rsa);
//指定解密的時候hash算法為md5
rsadeformatter.sethashalgorithm("md5");

if(rsadeformatter.verifysignature(hashbytedeformatter,deformatterdata))
{
return true;
}
else
{
return false;
}
}
catch(exception ex)
{
throw ex;
}
}

public bool signaturedeformatter(string p_strkeypublic, byte[] hashbytedeformatter, string p_strdeformatterdata)
{
try
{
byte[] deformatterdata;

system.security.cryptography.rsacryptoserviceprovider rsa = new system.security.cryptography.rsacryptoserviceprovider();

rsa.fromxmlstring(p_strkeypublic);
system.security.cryptography.rsapkcs1signaturedeformatter rsadeformatter = new system.security.cryptography.rsapkcs1signaturedeformatter(rsa);
//指定解密的時候hash算法為md5
rsadeformatter.sethashalgorithm("md5");

deformatterdata =convert.frombase64string(p_strdeformatterdata);

if(rsadeformatter.verifysignature(hashbytedeformatter,deformatterdata))
{
return true;
}
else
{
return false;
}
}
catch(exception ex)
{
throw ex;
}
}

public bool signaturedeformatter(string p_strkeypublic, string p_strhashbytedeformatter, string p_strdeformatterdata)
{
try
{
byte[] deformatterdata;
byte[] hashbytedeformatter;

hashbytedeformatter = convert.frombase64string(p_strhashbytedeformatter);
system.security.cryptography.rsacryptoserviceprovider rsa = new system.security.cryptography.rsacryptoserviceprovider();

rsa.fromxmlstring(p_strkeypublic);
system.security.cryptography.rsapkcs1signaturedeformatter rsadeformatter = new system.security.cryptography.rsapkcs1signaturedeformatter(rsa);
//指定解密的時候hash算法為md5
rsadeformatter.sethashalgorithm("md5");

deformatterdata =convert.frombase64string(p_strdeformatterdata);

if(rsadeformatter.verifysignature(hashbytedeformatter,deformatterdata))
{
return true;
}
else
{
return false;
}
}
catch(exception ex)
{
throw ex;
}
}


#endregion
#endregion

}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////
//frmrsacryptiontest.cs
///////////////////////////////////////////////////////////////////////////////////////////////////////////

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;

namespace rsaapplication
{
/// <summary>
/// frmrsacryptiontest 的摘要說明。
/// </summary>
public class frmrsacryptiontest : system.windows.forms.form
{
#region 必需的設計器變量
/// <summary>
/// 必需的設計器變量
/// </summary>
private system.windows.forms.button btnbuildkey;
private system.windows.forms.textbox txtkeypublic;
private system.windows.forms.textbox txtkeyprivate;
private system.componentmodel.container components = null;

private system.windows.forms.button btnrsaencrypt;
private system.windows.forms.textbox txtrsadecrypt;
private system.windows.forms.button btnrsadecrypt;
private system.windows.forms.textbox txtsource;
private system.windows.forms.textbox txtrsaencrypt;
private system.windows.forms.button btnsignature;

private system.windows.forms.button btndeformatter;
private system.windows.forms.button btngethashsignature;
private system.windows.forms.button btngethashdeformatter;
private system.windows.forms.textbox txtsignature;
private system.windows.forms.textbox txtgethashsignature;
private system.windows.forms.textbox txtgethashdeformatter;


private string m_strkeyprivate = "";
private string m_strkeypublic = "";

private string m_strhashbytesignature = "";
private string m_strhashbytedeformatter = "";
private string m_strencryptedsignaturedata = "";
#endregion

#region 構造函數
public frmrsacryptiontest()
{
//
// windows 窗體設計器支持所必需的
//
initializecomponent();

//
// todo: 在 initializecomponent 調用后添加任何構造函數代碼
//
}

/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}
#endregion

#region windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void initializecomponent()
{
this.btnbuildkey = new system.windows.forms.button();
this.txtkeypublic = new system.windows.forms.textbox();
this.txtkeyprivate = new system.windows.forms.textbox();
this.btnrsaencrypt = new system.windows.forms.button();
this.txtsource = new system.windows.forms.textbox();
this.txtrsaencrypt = new system.windows.forms.textbox();
this.txtrsadecrypt = new system.windows.forms.textbox();
this.btnrsadecrypt = new system.windows.forms.button();
this.btndeformatter = new system.windows.forms.button();
this.btnsignature = new system.windows.forms.button();
this.txtsignature = new system.windows.forms.textbox();
this.btngethashsignature = new system.windows.forms.button();
this.btngethashdeformatter = new system.windows.forms.button();
this.txtgethashsignature = new system.windows.forms.textbox();
this.txtgethashdeformatter = new system.windows.forms.textbox();
this.suspendlayout();
//
// btnbuildkey
//
this.btnbuildkey.location = new system.drawing.point(11, 17);
this.btnbuildkey.name = "btnbuildkey";
this.btnbuildkey.size = new system.drawing.size(77, 34);
this.btnbuildkey.tabindex = 0;
this.btnbuildkey.text = "產生密鑰";
this.btnbuildkey.click += new system.eventhandler(this.btnbuildkey_click);
//
// txtkeypublic
//
this.txtkeypublic.location = new system.drawing.point(137, 11);
this.txtkeypublic.multiline = true;
this.txtkeypublic.name = "txtkeypublic";
this.txtkeypublic.size = new system.drawing.size(602, 44);
this.txtkeypublic.tabindex = 1;
this.txtkeypublic.text = "";
//
// txtkeyprivate
//
this.txtkeyprivate.location = new system.drawing.point(137, 58);
this.txtkeyprivate.multiline = true;
this.txtkeyprivate.name = "txtkeyprivate";
this.txtkeyprivate.size = new system.drawing.size(602, 44);
this.txtkeyprivate.tabindex = 2;
this.txtkeyprivate.text = "";
//
// btnrsaencrypt
//
this.btnrsaencrypt.location = new system.drawing.point(11, 157);
this.btnrsaencrypt.name = "btnrsaencrypt";
this.btnrsaencrypt.size = new system.drawing.size(77, 34);
this.btnrsaencrypt.tabindex = 3;
this.btnrsaencrypt.text = "rsa加密";
this.btnrsaencrypt.click += new system.eventhandler(this.btnrsaencrypt_click);
//
// txtsource
//
this.txtsource.location = new system.drawing.point(137, 108);
this.txtsource.multiline = true;
this.txtsource.name = "txtsource";
this.txtsource.size = new system.drawing.size(602, 44);
this.txtsource.tabindex = 4;
this.txtsource.text = "字串不能太長j——km,.ewm.m, .vkj中國福建";
//
// txtrsaencrypt
//
this.txtrsaencrypt.location = new system.drawing.point(137, 155);
this.txtrsaencrypt.multiline = true;
this.txtrsaencrypt.name = "txtrsaencrypt";
this.txtrsaencrypt.size = new system.drawing.size(602, 44);
this.txtrsaencrypt.tabindex = 5;
this.txtrsaencrypt.text = "";
//
// txtrsadecrypt
//
this.txtrsadecrypt.location = new system.drawing.point(137, 203);
this.txtrsadecrypt.multiline = true;
this.txtrsadecrypt.name = "txtrsadecrypt";
this.txtrsadecrypt.size = new system.drawing.size(602, 44);
this.txtrsadecrypt.tabindex = 6;
this.txtrsadecrypt.text = "";
//
// btnrsadecrypt
//
this.btnrsadecrypt.location = new system.drawing.point(11, 202);
this.btnrsadecrypt.name = "btnrsadecrypt";
this.btnrsadecrypt.size = new system.drawing.size(77, 34);
this.btnrsadecrypt.tabindex = 7;
this.btnrsadecrypt.text = "rsa解密";
this.btnrsadecrypt.click += new system.eventhandler(this.btnrsadecrypt_click);
//
// btndeformatter
//
this.btndeformatter.location = new system.drawing.point(11, 396);
this.btndeformatter.name = "btndeformatter";
this.btndeformatter.size = new system.drawing.size(77, 34);
this.btndeformatter.tabindex = 10;
this.btndeformatter.text = "rsa驗證";
this.btndeformatter.click += new system.eventhandler(this.btndeformatter_click);
//
// btnsignature
//
this.btnsignature.location = new system.drawing.point(11, 297);
this.btnsignature.name = "btnsignature";
this.btnsignature.size = new system.drawing.size(77, 34);
this.btnsignature.tabindex = 9;
this.btnsignature.text = "rsa簽名";
this.btnsignature.click += new system.eventhandler(this.btnsignature_click);
//
// txtsignature
//
this.txtsignature.location = new system.drawing.point(137, 298);
this.txtsignature.multiline = true;
this.txtsignature.name = "txtsignature";
this.txtsignature.size = new system.drawing.size(602, 44);
this.txtsignature.tabindex = 11;
this.txtsignature.text = "";
//
// btngethashsignature
//
this.btngethashsignature.location = new system.drawing.point(11, 252);
this.btngethashsignature.name = "btngethashsignature";
this.btngethashsignature.size = new system.drawing.size(117, 36);
this.btngethashsignature.tabindex = 13;
this.btngethashsignature.text = "獲取哈稀碼(簽名)";
this.btngethashsignature.click += new system.eventhandler(this.btngethashsignature_click);
//
// btngethashdeformatter
//
this.btngethashdeformatter.location = new system.drawing.point(11, 348);
this.btngethashdeformatter.name = "btngethashdeformatter";
this.btngethashdeformatter.size = new system.drawing.size(117, 36);
this.btngethashdeformatter.tabindex = 14;
this.btngethashdeformatter.text = "獲取哈稀碼(驗證)";
this.btngethashdeformatter.click += new system.eventhandler(this.btngethashdeformatter_click);
//
// txtgethashsignature
//
this.txtgethashsignature.location = new system.drawing.point(137, 251);
this.txtgethashsignature.multiline = true;
this.txtgethashsignature.name = "txtgethashsignature";
this.txtgethashsignature.size = new system.drawing.size(602, 44);
this.txtgethashsignature.tabindex = 15;
this.txtgethashsignature.text = "";
//
// txtgethashdeformatter
//
this.txtgethashdeformatter.location = new system.drawing.point(137, 346);
this.txtgethashdeformatter.multiline = true;
this.txtgethashdeformatter.name = "txtgethashdeformatter";
this.txtgethashdeformatter.size = new system.drawing.size(602, 44);
this.txtgethashdeformatter.tabindex = 16;
this.txtgethashdeformatter.text = "";
//
// frmrsacryptiontest
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(764, 444);
this.controls.add(this.txtgethashdeformatter);
this.controls.add(this.txtgethashsignature);
this.controls.add(this.txtsignature);
this.controls.add(this.txtrsadecrypt);
this.controls.add(this.txtrsaencrypt);
this.controls.add(this.txtsource);
this.controls.add(this.txtkeyprivate);
this.controls.add(this.txtkeypublic);
this.controls.add(this.btngethashdeformatter);
this.controls.add(this.btngethashsignature);
this.controls.add(this.btndeformatter);
this.controls.add(this.btnsignature);
this.controls.add(this.btnrsadecrypt);
this.controls.add(this.btnrsaencrypt);
this.controls.add(this.btnbuildkey);
this.name = "frmrsacryptiontest";
this.text = "rsa加密解密";
this.resumelayout(false);

}
#endregion

#region 應用程序的主入口點
/// <summary>
/// 應用程序的主入口點
/// </summary>
[stathread]
static void main()
{
application.run(new frmrsacryptiontest());
}
#endregion

#region 產生密鑰

private void btnbuildkey_click(object sender, system.eventargs e)
{

try
{
rsacryption rc = new rsacryption();

rc.rsakey(out m_strkeyprivate, out m_strkeypublic);

this.txtkeyprivate.text = m_strkeyprivate;
this.txtkeypublic.text = m_strkeypublic;
}
catch(exception ex)
{
messagebox.show(this,ex.message,"錯誤",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.error);
}
}
#endregion

#region 加密解密

private void btnrsaencrypt_click(object sender, system.eventargs e)
{
try
{
rsacryption rc = new rsacryption();

this.txtrsaencrypt.text = rc.rsaencrypt(m_strkeypublic, this.txtsource.text);
}
catch(exception ex)
{
messagebox.show(this,ex.message,"錯誤",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.error);
}
}

private void btnrsadecrypt_click(object sender, system.eventargs e)
{
try
{
rsacryption rc = new rsacryption();

this.txtrsadecrypt.text = rc.rsadecrypt(m_strkeyprivate, this.txtrsaencrypt.text);
}
catch(exception ex)
{
messagebox.show(this,ex.message,"錯誤",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.error);
}
}

#endregion

#region 簽名、驗證

#region 獲取hash碼---針對簽名

private void btngethashsignature_click(object sender, system.eventargs e)
{
try
{
rsacryption rc = new rsacryption();

if( rc.gethash(this.txtsource.text,ref m_strhashbytesignature) == false)
{
messagebox.show(this,"取hash碼錯誤!","提示",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.warning);
}

this.txtgethashsignature.text = m_strhashbytesignature;
}
catch(exception ex)
{
messagebox.show(this,ex.message,"錯誤",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.error);
}
}
#endregion

#region 簽名
private void btnsignature_click(object sender, system.eventargs e)
{
try
{
rsacryption rc = new rsacryption();

if( rc.signatureformatter(m_strkeyprivate,m_strhashbytesignature, ref m_strencryptedsignaturedata) == false)
{
messagebox.show(this,"rsa數字簽名錯誤!","提示",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.warning);
}

this.txtsignature.text = m_strencryptedsignaturedata;
}
catch(exception ex)
{
messagebox.show(this,ex.message,"錯誤",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.error);
}
}
#endregion

#region 獲取hash碼---針對驗證
private void btngethashdeformatter_click(object sender, system.eventargs e)
{
try
{
rsacryption rc = new rsacryption();

if( rc.gethash(this.txtsource.text,ref m_strhashbytedeformatter) == false)
{
messagebox.show(this,"取hash碼錯誤!","提示",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.warning);
}

this.txtgethashdeformatter.text = m_strhashbytedeformatter;
}
catch(exception ex)
{
messagebox.show(this,ex.message,"錯誤",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.error);
}
}
#endregion

#region 驗證
private void btndeformatter_click(object sender, system.eventargs e)
{
try
{
rsacryption rc = new rsacryption();

if( rc.signaturedeformatter(m_strkeypublic,m_strhashbytedeformatter, m_strencryptedsignaturedata) == false)
{
messagebox.show(this,"身份驗證失敗!","提示",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.warning);
}
else
{
messagebox.show(this,"身份驗證通過!","提示",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.warning);
}
}
catch(exception ex)
{
messagebox.show(this,ex.message,"錯誤",system.windows.forms.messageboxbuttons.ok,system.windows.forms.messageboxicon.error);
}
}
#endregion

#endregion

}
}



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌审旗| 醴陵市| 田阳县| 钟祥市| 洱源县| 进贤县| 金昌市| 界首市| 江油市| 阿克苏市| 沾化县| 西畴县| 三台县| 大足县| 来凤县| 黄梅县| 鄂尔多斯市| 灌云县| 靖远县| 会同县| 吴旗县| 哈尔滨市| 鲁甸县| 诸暨市| 宜城市| 寻乌县| 郸城县| 维西| 通化县| 孙吴县| 湄潭县| 渝北区| 改则县| 延安市| 开化县| 秦皇岛市| 普安县| 贡嘎县| 察哈| 大名县| 黄骅市|