手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#中字符串的加密的源码
C#中字符串的加密的源码
摘要:可以用DSA和RSA,如:usingSystem;usingSystem.Text;usingSystem.Security.Cryptog...

可以用DSA和RSA,如:

usingSystem;

usingSystem.Text;

usingSystem.Security.Cryptography;

classdsacrypto_SignData{

publicstaticvoidMain(String[]args){

//先要将字符串转换为字节数组,这与编码有关。

Stringstr="thisisatest.";

byte[]bytes=Encoding.ASCII.GetBytes(str);

//选择签名方式,有RSA和DSA

DSACryptoServiceProviderdsac=newDSACryptoServiceProvider();

byte[]sign=dsac.SignData(bytes);

//sign便是出来的签名结果。

//下面是认证了

DSACryptoServiceProviderdsac2=newDSACryptoServiceProvider();

dsac2.FromXmlString(dsac.ToXmlString(false));

boolver=dsac2.VerifyData(bytes,sign);

if(ver){

Console.WriteLine("通过");

}else{

Console.WriteLine("不能通过");

}

}

}

RSA类似,不过RSA比DSA慢得多,但比DSA安全。RSA可以选择关键字的大小,越大越安全

【C#中字符串的加密的源码】相关文章:

C#中方括号[]的语法及作用介绍

C# 位运算符整理

将字符串转换成System.Drawing.Color类型的方法

C#中日期时间的简单操作

C#.net中的类型转换详细介绍

c# 曲线图生成代码

C#中的yield关键字的使用方法介绍

在C#中 webbrowser的使用心得

C#中HashTable的定义与使用方法

C# DES加密算法中向量的作用详细解析

精品推荐
分类导航