当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > C#中字符串的加密

ASP.NET
Web服务器控件:LinkButton控件
Web服务器控件:ListBox控件
Web服务器控件:ListItem控件
Web服务器控件:Literal控件
Web服务器控件:Panel控件
Web服务器控件:PlaceHolder控件
Web服务器控件:RadioButton控件
Web服务器控件:RadioButtonList控件
Web服务器控件:BulletedList控件
Web服务器控件:Style控件
Web服务器控件:Table控件
Web服务器控件:TableCell控件
Web服务器控件:TableRow控件
Web服务器控件:TextBox控件
Web服务器控件:XML控件
Validation服务器控件:CompareValidator控件
Validation服务器控件:CustomValidator控件
Validation服务器控件:RangeValidator控件
Validation服务器控件:RegularExpressionValidator控件
Validation服务器控件:RequiredFieldValidator控件

ASP.NET 中的 C#中字符串的加密


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 84 ::
收藏到网摘: n/a


可以用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可以选择关键字的大小,越大越安全