字符串的加密和解密方法? http://expert.csdn.net/Expert/topic/1866/1866394.xml?temp=.2852289 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用RSA进行数字签名,非常安全! http://expert.csdn.net/Expert/topic/1925/1925045.xml?temp=9.141177E-02 可以用DSA和RSA,如:using System;using System.Text;using System.Security.Cryptography; class dsacrypto_SignData { public static void Main(String[] args){ //先要将字符串转换为字节数组,这与编码有关。 String str = "this is a test."; byte[] bytes = Encoding.ASCII.GetBytes(str); //选择签名方式,有RSA和DSA DSACryptoServiceProvider dsac = new DSACryptoServiceProvider(); byte[] sign = dsac.SignData(bytes); //sign便是出来的签名结果。 //下面是认证了 DSACryptoServiceProvider dsac2 = new DSACryptoServiceProvider(); dsac2.FromXmlString(dsac.ToXmlString(false)); bool ver = dsac2.VerifyData(bytes, sign); if (ver) { Console.WriteLine("通过"); } else { Console.WriteLine("不能通过"); } } }RSA类似,不过RSA比DSA慢得多,但比DSA安全。RSA可以选择关键字的大小,越大越安全 .NET中加密和解密的实现方法http://www.oscars.cseek.com/20030422/1664891.shtml using System.IO;using System.Security.Cryptography;using System;namespace com.billdawson.crypto{ class TextFileCrypt { public static void Main(string[] args) { string file = args[0]; string tempfile = Path.GetTempFileName(); //打开指定的文件 FileStream fsIn = File.Open(file,FileMode.Open, FileAccess.Read); FileStream fsOut = File.Open(tempfile, FileMode.Open, FileAccess.Write); //定义对称算法对象实例和接口 SymmetricAlgorithm symm = new RijndaelManaged(); ICryptoTransform transform = symm.CreateEncryptor(); CryptoStream cstream = new CryptoStream(fsOut,transform, CryptoStreamMode.Write); BinaryReader br = new BinaryReader(fsIn); // 读取源文件到cryptostream cstream.Write(br.ReadBytes((int)fsIn.Length),0,(int)fsIn.Length); cstream.FlushFinalBlock(); cstream.Close(); fsIn.Close(); fsOut.Close(); Console.WriteLine("created encrypted file {0}", tempfile); Console.WriteLine("will now decrypt and show contents"); // 反向操作--解密刚才加密的临时文件 fsIn = File.Open(tempfile,FileMode.Open,FileAccess.Read); transform = symm.CreateDecryptor(); cstream = new CryptoStream(fsIn,transform, CryptoStreamMode.Read); StreamReader sr = new StreamReader(cstream); Console.WriteLine("decrypted file text: " + sr.ReadToEnd()); fsIn.Close(); } }} 求教,下面代码如何重构? C#如何响应连续按键?比如按两下SHIFT后调用一个方法? c#里面的string数组是个怎么回事? 一个 复杂的问题, 望各位 高手前来指教 两种 绑定方法 有什么区别 ComboBox绑定问题? 如何在datagrid列中添加下拉列表 comboBox数据绑定显示问题~在线等~! 高手请进,在线等 如何能精通UML和C#? [100分醒目]谁能给我一个简单的向服务器发送命令的例子[100分醒目] 保证你现在和未来不失业的十种关键技术(转载)
using System;
using System.Text;
using System.Security.Cryptography; class dsacrypto_SignData {
public static void Main(String[] args){
//先要将字符串转换为字节数组,这与编码有关。
String str = "this is a test.";
byte[] bytes = Encoding.ASCII.GetBytes(str);
//选择签名方式,有RSA和DSA
DSACryptoServiceProvider dsac = new DSACryptoServiceProvider();
byte[] sign = dsac.SignData(bytes);
//sign便是出来的签名结果。 //下面是认证了
DSACryptoServiceProvider dsac2 = new DSACryptoServiceProvider();
dsac2.FromXmlString(dsac.ToXmlString(false));
bool ver = dsac2.VerifyData(bytes, sign);
if (ver) {
Console.WriteLine("通过");
} else {
Console.WriteLine("不能通过");
}
}
}RSA类似,不过RSA比DSA慢得多,但比DSA安全。RSA可以选择关键字的大小,越大越安全
using System.Security.Cryptography;
using System;
namespace com.billdawson.crypto
{
class TextFileCrypt
{
public static void Main(string[] args)
{
string file = args[0];
string tempfile = Path.GetTempFileName();
//打开指定的文件
FileStream fsIn = File.Open(file,FileMode.Open,
FileAccess.Read);
FileStream fsOut = File.Open(tempfile, FileMode.Open,
FileAccess.Write);
//定义对称算法对象实例和接口
SymmetricAlgorithm symm = new RijndaelManaged();
ICryptoTransform transform = symm.CreateEncryptor();
CryptoStream cstream = new CryptoStream(fsOut,transform,
CryptoStreamMode.Write); BinaryReader br = new BinaryReader(fsIn);
// 读取源文件到cryptostream
cstream.Write(br.ReadBytes((int)fsIn.Length),0,(int)fsIn.Length);
cstream.FlushFinalBlock();
cstream.Close();
fsIn.Close();
fsOut.Close(); Console.WriteLine("created encrypted file {0}", tempfile);
Console.WriteLine("will now decrypt and show contents"); // 反向操作--解密刚才加密的临时文件
fsIn = File.Open(tempfile,FileMode.Open,FileAccess.Read);
transform = symm.CreateDecryptor();
cstream = new CryptoStream(fsIn,transform,
CryptoStreamMode.Read); StreamReader sr = new StreamReader(cstream);
Console.WriteLine("decrypted file text: " + sr.ReadToEnd());
fsIn.Close();
}
}
}