C# 加密-TripleDES
TripleDES
属对称加密,对称加密在加密和解密时都使用相同的密钥,速度快。
TripleDESCryptoServiceProvider 的名称空间是:
System.Security.Cryptography
byte[] plaintextBuffer = System.Text.Encoding.UTF8.GetBytes("明文");
//加密
TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
ICryptoTransform transform = tripleDES.CreateEncryptor();
byte[] cipherTextBuffer = transform.TransformFinalBlock(plaintextBuffer, 0, plaintextBuffer.Length);
lbl.Text = Convert.ToBase64String(cipherTextBuffer) + "<br />";
transform.Dispose();
//解密
TripleDESCryptoServiceProvider tripleDES2 = new TripleDESCryptoServiceProvider();
ICryptoTransform transform2 = tripleDES2.CreateDecryptor(tripleDES.Key, tripleDES.IV);
byte[] decryption = transform2.TransformFinalBlock(cipherTextBuffer, 0, cipherTextBuffer.Length);
lbl.Text += System.Text.Encoding.UTF8.GetString(decryption) + "<br />";
transform2.Dispose();
解密时,使用加密的 Key 和 IV。
相关文档:
1 NameSapce
1 1个namespace里面可以有多个类
2 namespace和cs文件是多对多的关系。
3 调用另一个namespace的声明,可以使用using <namespace> ,然后直接调用类名,或者使用namespace.类名来调用
4 namespace支持别名(alias) using namespace = namespace.classname,如using m ......
熟悉ruby on rails的开发员都知道,在ruby中,有一个很重要的特性,就是能够实现元编程,特别是在用于开发Web应用的rails框架中,用的特别多。在rails中,要创建一个动态方法并与数据库表字段相关联,主要的的步骤大概有这些:
1、首先配置好数据库的连接。
2、创建一个ActiveRecord模型,这个模型与数据库的表名称有一定 ......
C#操作数据库,写来写去就那么几句套话,烦。尽管有SqlHelper之类的辅助类,但还是有一堆参数要自己填,继续烦。最近有朋友问起自动代码生成工具的原理,那今天就说说我的思路吧。我只会MS SQL SERVER,所以就只拿它说事儿了。
其实大的思路很简单,获取数据库中的比较原子的对象,比如字段、参数等,并找出数据库各字段类 ......
在 ASP.NET 中可以非常方便地执行 MD5
或 SHA1 加密。
<%@ Import Namespace="System.Web.Security" %>
FormsAuthentication.HashPasswordForStoringInConfigFile
只需要两步,第一步引入名称空间
(该名称空间也可以省略引用),第二步执行加密函数。
FormsAuthentication.HashPasswordForStoringI ......