复制代码 代码如下:
<form runat="server">
随机生成密钥:<asp:Button runat="server" Text="随机生成密钥" /><br />
公钥:<asp:TextBox runat="server" TextMode="MultiLine" ReadOnly="True"></asp:TextBox><br />
私钥:<asp:TextBox runat="server" TextMode="MultiLine" ReadOnly="True"></asp:TextBox><br /><hr />
<br />
生成签名:<br />
原文:
<asp:TextBox runat="server" TextMode="MultiLine"></asp:TextBox> <br />
私钥:
<asp:TextBox runat="server" TextMode="MultiLine"></asp:TextBox><br />
签名:
<asp:TextBox runat="server" TextMode="MultiLine" ReadOnly="True"></asp:TextBox>
<br />
<asp:Button runat="server" Text="生成签名" />
<br />
<br /><hr />
<br />
验证签名:<br />
原文:<asp:TextBox runat="server" TextMode="MultiLine"></asp:TextBox><br />
公钥:<asp:TextBox runat="server" TextMode="MultiLine"></asp:TextBox><br />
签名:<asp:TextBox runat="server" TextMode="MultiLine"></asp:TextBox>
<br />
<asp:Button runat="server" Text="验证签名" />
</form>
复制代码 代码如下:
/// <summary>
/// 生成签名
/// </summary>
/// <param></param>
/// <param></param>
protected void Button1_Click(object sender, EventArgs e)
{
DSACryptoServiceProvider objdsa = new DSACryptoServiceProvider();
objdsa.FromXmlString(tbxKey.Text);
byte[] source = System.Text.UTF8Encoding.UTF8.GetBytes(tbxContent.Text);
//数字签名
tbxSign.Text = BitConverter.ToString(objdsa.SignData(source));
}
/// <summary>
/// 随机生成密钥
/// </summary>
/// <param></param>
/// <param></param>
protected void btncreateMY_Click(object sender, EventArgs e)
{
DSACryptoServiceProvider objdsa = new DSACryptoServiceProvider();
tbxcreateMY_publicKey.Text = objdsa.ToXmlString(false);
tbxcreateMY_key.Text = objdsa.ToXmlString(true);
}
/// <summary>
/// 验证签名
/// </summary>
/// <param></param>
/// <param></param>
protected void Button3_Click(object sender, EventArgs e)
{
DSACryptoServiceProvider objdsa = new DSACryptoServiceProvider();
byte[] fileHashValue = new SHA1CryptoServiceProvider().ComputeHash(System.Text.UTF8Encoding.UTF8.GetBytes(tbxContentYZ.Text));
string[] strSplit = tbxSignYZ.Text.Split('-');
byte[] SignedHash = new byte[strSplit.Length];
for (int i = 0; i < strSplit.Length; i++)
SignedHash[i] = byte.Parse(strSplit[i], System.Globalization.NumberStyles.AllowHexSpecifier);
objdsa.FromXmlString(tbxPublickeyYZ.Text);
bool ret = objdsa.VerifySignature(fileHashValue, SignedHash);
Response.Write(ret.ToString());
// Qcd.Core.Web.Messages.ShowDialog(ret.ToString());
}
新闻热点
疑难解答
图片精选