C# 加密-Rijndael
Rijndael
属对称加密,对称加密在加密和解密时都使用相同的密钥。2000 年 10 月,NIST 选择 Rijndael(发音为 "Rhine dale")作为 AES 算法,用以取代 DES。
Rijndael 的名称空间是:
System.Security.Cryptography
byte[] plaintextBuffer = System.Text.Encoding.UTF8.GetBytes("明文");
//加密
Rijndael rijndael = Rijndael.Create();
ICryptoTransform transform = rijndael.CreateEncryptor();
byte[] cipherTextBuffer = transform.TransformFinalBlock(plaintextBuffer, 0, plaintextBuffer.Length);
lbl.Text = Convert.ToBase64String(cipherTextBuffer) + "<br />";
transform.Dispose();
//解密
Rijndael rijndael2 = Rijndael.Create();
ICryptoTransform transform2 = rijndael2.CreateDecryptor(rijndael.Key, rijndael.IV);
byte[] decryption = transform2.TransformFinalBlock(cipherTextBuffer, 0, cipherTextBuffer.Length);
lbl.Text += System.Text.Encoding.UTF8.GetString(decryption) + "<br />";
transform2.Dispose();
解密时,使用加密的 Key 和 IV。
相关文档:
属性是类中可以像类的字段一样访问的方法。属性可以为类的字段提供保护,避免字段在对象不知道情况下被修改。C#通过属性来修改,读写或计算私有的字段的值。属性相当于对字段访问的封装。下例子可以清楚说明哟:
class Person
{
......
Eval("")和Bind("") 这两种一个单向绑定,一个双向绑定,bind是双向绑定,但需数据源支持
ASP.NET 2.0改善了模板中的数据绑定操作,把v1.x中的数据绑定语法DataBinder.Eval(Container.DataItem, fieldname)简化为Eval(fieldname)。Eval方法与DataBinder.Eval一样可以接受一个可选的格式化字符串参 ......
C#操作数据库,写来写去就那么几句套话,烦。尽管有SqlHelper之类的辅助类,但还是有一堆参数要自己填,继续烦。最近有朋友问起自动代码生成工具的原理,那今天就说说我的思路吧。我只会MS SQL SERVER,所以就只拿它说事儿了。
其实大的思路很简单,获取数据库中的比较原子的对象,比如字段、参数等,并找出数据库各字段类 ......
在 ASP.NET 中可以非常方便地执行 MD5
或 SHA1 加密。
<%@ Import Namespace="System.Web.Security" %>
FormsAuthentication.HashPasswordForStoringInConfigFile
只需要两步,第一步引入名称空间
(该名称空间也可以省略引用),第二步执行加密函数。
FormsAuthentication.HashPasswordForStoringI ......