基本信息
源码名称:RSA加签验签测试工具&源码
源码大小:0.65M
文件格式:.rar
开发语言:C#
更新时间:2019-04-16
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Security.Cryptography;
using System.IO;
namespace rsa
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
RSAHelper helper = new RSAHelper();
string halg = "MD5";//SHA1 MD5 SHA256
Dictionary<string, string> sign_str = Lib.Decode(this.textBox1.Text.Trim());
string url = Lib.GetParamSrc(sign_str);
string sign_str_1 = helper.Sign(url, halg);
this.richTextBox1.Text = "sign_str_1:" sign_str_1;
this.richTextBox1.Text = "\r\n" "\r\n";
this.textBox2.Text = sign_str_1;
}
private void button2_Click(object sender, EventArgs e)
{
string content, publicCSharpKey;
content = this.textBox1.Text.Trim();
Dictionary<string, string> sign_str = Lib.Decode(content);
string url = Lib.GetParamSrc(sign_str);
publicCSharpKey = Lib.GetCSharpPublickey();
string halg = "MD5";//SHA1 MD5 SHA256
string sing_res = this.textBox2.Text.Trim();
this.richTextBox1.Text = "传递签名:" sing_res;
this.richTextBox1.Text = "\r\n";
this.richTextBox1.Text = "签名一致:" RSAHelper.VerifyData(publicCSharpKey, url, sing_res, halg);
}
private void button4_Click(object sender, EventArgs e)
{
this.textBox2.Text = "";
this.richTextBox1.Clear();
}
public static string DecodeBase64(string code_type, string code)
{
string decode = "";
byte[] bytes = Convert.FromBase64String(code);
try
{
decode = Encoding.GetEncoding(code_type).GetString(bytes);
}
catch
{
decode = code;
}
return decode;
}
public static string EncodeBase64(string code_type, string code)
{
string encode = "";
byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code);
try
{
encode = Convert.ToBase64String(bytes);
}
catch
{
encode = code;
}
return encode;
}
private void button8_Click(object sender, EventArgs e)
{
GenerateKeys();
}
public static void GenerateKeys()
{
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
using (StreamWriter writer = new StreamWriter("PrivateKey.xml")) //这个文件要保密...
{
writer.WriteLine(rsa.ToXmlString(true));
}
using (StreamWriter writer = new StreamWriter("PublicKey.xml"))
{
writer.WriteLine(rsa.ToXmlString(false));
}
}
}
}