加密字符串,没有什么说的,说明都在代码里面。看代码吧~
//定义SHA1对象
System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
//获取加密后密文字节数组
//注意编码UTF8、UTF7、Unicode等的选择,例如
//byte[] bytResult = sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strName));
//这里编码采用系统默认编码
byte[] bytResult = sha1.ComputeHash(System.Text.Encoding.Default.GetBytes(strName));
//转换成字符串
strName = BitConverter.ToString(bytResult);
System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
//获取加密后密文字节数组
//注意编码UTF8、UTF7、Unicode等的选择,例如
//byte[] bytResult = sha1.ComputeHash(System.Text.Encoding.UTF8.GetBytes(strName));
//这里编码采用系统默认编码
byte[] bytResult = sha1.ComputeHash(System.Text.Encoding.Default.GetBytes(strName));
//转换成字符串
strName = BitConverter.ToString(bytResult);
或者有更简单的:
str = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(strInput,"SHA1");
可以通过对加密后的字符串作进一步处理或者加入公共密码再加密以求更弓虽大的加密效果。
MD5方法同理,更改一下相关类或输入即可。