static void Main(string[] args)
{
string s = "老王头,这周又开始忙了!";
byte[] data;
RSACryptoServiceProvider rsp = new RSACryptoServiceProvider();
System.IO.File.WriteAllText(@"D:\wangran\公钥.xml", rsp.ToXmlString(false));
System.IO.File.WriteAllText(@"D:\wangran\密钥.xml", rsp.ToXmlString(true));
//byte[] 公钥 = rsp.ExportCspBlob(false);
byte[] 密钥 = rsp.ExportCspBlob(true);//负责解密
//System.IO.File.WriteAllText(@"D:\wangran\公钥.txt", Convert.ToBase64String(公钥));
System.IO.File.WriteAllText(@"D:\wangran\密钥.txt", Convert.ToBase64String(密钥));
data = System.Text.UTF8Encoding.UTF8.GetBytes(s);
byte[] data_1 = rsp.SignData(data, "md5");
byte[] data1 = rsp.Encrypt(data, false);
Console.WriteLine(
System.Text.UTF8Encoding.UTF8.GetString(data));
Console.WriteLine(
System.Text.UTF8Encoding.UTF8.GetString(data_1));
rsp = new RSACryptoServiceProvider();
//rsp.ImportCspBlob(公钥);
rsp.FromXmlString(System.IO.File.ReadAllText(@"D:\wangran\公钥.xml"));
//公钥只签名与加密,不解密
byte[] data2 = rsp.Encrypt(data, false);
Console.WriteLine(Convert.ToBase64String(data1));
Console.WriteLine(Convert.ToBase64String(data2));
//验签
Console.WriteLine(rsp.VerifyData(data, "md5", data_1));
rsp = new RSACryptoServiceProvider();
//rsp.ImportCspBlob(公钥);
rsp.FromXmlString(System.IO.File.ReadAllText(@"D:\wangran\公钥.xml"));
data2 = rsp.Encrypt(data, false);
Console.WriteLine(Convert.ToBase64String(data1));
Console.WriteLine(Convert.ToBase64String(data2));
//验签
Console.WriteLine(rsp.VerifyData(data, "md5", data_1));
}
{
string s = "老王头,这周又开始忙了!";
byte[] data;
RSACryptoServiceProvider rsp = new RSACryptoServiceProvider();
System.IO.File.WriteAllText(@"D:\wangran\公钥.xml", rsp.ToXmlString(false));
System.IO.File.WriteAllText(@"D:\wangran\密钥.xml", rsp.ToXmlString(true));
//byte[] 公钥 = rsp.ExportCspBlob(false);
byte[] 密钥 = rsp.ExportCspBlob(true);//负责解密
//System.IO.File.WriteAllText(@"D:\wangran\公钥.txt", Convert.ToBase64String(公钥));
System.IO.File.WriteAllText(@"D:\wangran\密钥.txt", Convert.ToBase64String(密钥));
data = System.Text.UTF8Encoding.UTF8.GetBytes(s);
byte[] data_1 = rsp.SignData(data, "md5");
byte[] data1 = rsp.Encrypt(data, false);
Console.WriteLine(
System.Text.UTF8Encoding.UTF8.GetString(data));
Console.WriteLine(
System.Text.UTF8Encoding.UTF8.GetString(data_1));
rsp = new RSACryptoServiceProvider();
//rsp.ImportCspBlob(公钥);
rsp.FromXmlString(System.IO.File.ReadAllText(@"D:\wangran\公钥.xml"));
//公钥只签名与加密,不解密
byte[] data2 = rsp.Encrypt(data, false);
Console.WriteLine(Convert.ToBase64String(data1));
Console.WriteLine(Convert.ToBase64String(data2));
//验签
Console.WriteLine(rsp.VerifyData(data, "md5", data_1));
rsp = new RSACryptoServiceProvider();
//rsp.ImportCspBlob(公钥);
rsp.FromXmlString(System.IO.File.ReadAllText(@"D:\wangran\公钥.xml"));
data2 = rsp.Encrypt(data, false);
Console.WriteLine(Convert.ToBase64String(data1));
Console.WriteLine(Convert.ToBase64String(data2));
//验签
Console.WriteLine(rsp.VerifyData(data, "md5", data_1));
}