关于.NET加密技术
来源:互联网 发布:淘宝库存怎么导出 编辑:程序博客网 时间:2024/05/16 18:14
导读:
我现在网站用户密码加密用的是.net自带的
FormsAuthentication.HashPasswordForStoringInConfigFile(Password,"MD5");
//加密密码变成32位小写字符串
pass= FormsAuthentication.HashPasswordForStoringInConfigFile(pass,"md5");
pass = pass.ToLower();
***************************************
哈希加密密码
using System.Web.Security;
password = FormsAuthentication.HashPasswordForStoringInConfigFile(password + dr["注册IP"], "SHA1");
关于加密:
对流可以执行对称加密,因此对称加密对于加密大量的数据很有用。对少量字节执行不对称加密,因此不对称加密只对少量的数据有用
在ASP.NET中实现加密非常容易。.NET SDK中提供了FormsAuthentication类,其中的HashPasswordForStoringInConfigFile方法可直接使用MD5
和SHA1算法。
例: MD5.Text = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text,"MD5");
//SHA1 use FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text,"SHA1");
加密用于达到以下目的:
保密性:防止用户的标识或数据被读取。
数据完整性:防止数据被更改。
身份验证:确保数据发自特定的一方
私钥加密
私钥加密又称为对称加密,因为同一密钥既用于加密又用于解密。私钥加密算法非常快(与公钥算法相比),特别适用于对较大的数据流执行
加密转换。它使用一个密钥和一个初始化向量 (IV)对数据执行加密转换
NET Framework 提供以下实现私钥加密算法的类:
DESCryptoServiceProvider
RC2CryptoServiceProvider
RijndaelManaged
TripleDESCryptoServiceProvider
DESCryptoServiceProvider 类
示例使用具有指定 Key 和初始化向量 (IV) 的 DESCryptoServiceProvider,加密 inName指定的文件,并将加密结果输出到 outName 指定的
文件。
private static void EncryptData(String inName, String outName, byte[] desKey, byte[] desIV)
{
//Create the file streams to handle the input and output files.
FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
fout.SetLength(0);
//Create variables to help with read and write.
byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
long rdlen =0; //This is the total number of bytes written.
long totlen = fin.Length; //This is the total length of the input file.
int len; //This is the number of bytes to be written at a time.
DES des = new DESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);
Console.WriteLine("Encrypting...");
//Read from the input file, then encrypt and write to the output file.
while(rdlen {
len = fin.Read(bin, 0, 100);
encStream.Write(bin, 0, len);
rdlen = rdlen + len;
Console.WriteLine("{0} bytes processed", rdlen);
}
encStream.Close();
fout.Close();
fin.Close();
}
[Visual Basic, C#] 可以相同的方法进行解密;使用 CreateDecryptor而不是 CreateEncryptor。必须使用加密该文件所用的同一 Key 和
IV 进行解密。
RC2CryptoServiceProvider 类
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
namespace RC2CryptoServiceProvider_Examples
{
class MyMainClass
{
public static void Main()
{
string original = "This is a much longer string of data than a public/private key algorithm will accept.";
string roundtrip;
ASCIIEncoding textConverter = new ASCIIEncoding();
RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();
byte[] fromEncrypt;
byte[] encrypted;
byte[] toEncrypt;
byte[] key;
byte[] IV;
Console.WriteLine("Effective key size is {0} bits.", rc2CSP.EffectiveKeySize);
//Create a new key and initialization vector.
rc2CSP.GenerateKey();
rc2CSP.GenerateIV();
//Get the key and IV.
key = rc2CSP.Key;
本文转自
http://blog.sina.com.cn/s/blog_3f33dac1010003zp.html
我现在网站用户密码加密用的是.net自带的
FormsAuthentication.HashPasswordForStoringInConfigFile(Password,"MD5");
//加密密码变成32位小写字符串
pass= FormsAuthentication.HashPasswordForStoringInConfigFile(pass,"md5");
pass = pass.ToLower();
***************************************
哈希加密密码
using System.Web.Security;
password = FormsAuthentication.HashPasswordForStoringInConfigFile(password + dr["注册IP"], "SHA1");
关于加密:
对流可以执行对称加密,因此对称加密对于加密大量的数据很有用。对少量字节执行不对称加密,因此不对称加密只对少量的数据有用
在ASP.NET中实现加密非常容易。.NET SDK中提供了FormsAuthentication类,其中的HashPasswordForStoringInConfigFile方法可直接使用MD5
和SHA1算法。
例: MD5.Text = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text,"MD5");
//SHA1 use FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text,"SHA1");
加密用于达到以下目的:
保密性:防止用户的标识或数据被读取。
数据完整性:防止数据被更改。
身份验证:确保数据发自特定的一方
私钥加密
私钥加密又称为对称加密,因为同一密钥既用于加密又用于解密。私钥加密算法非常快(与公钥算法相比),特别适用于对较大的数据流执行
加密转换。它使用一个密钥和一个初始化向量 (IV)对数据执行加密转换
NET Framework 提供以下实现私钥加密算法的类:
DESCryptoServiceProvider
RC2CryptoServiceProvider
RijndaelManaged
TripleDESCryptoServiceProvider
DESCryptoServiceProvider 类
示例使用具有指定 Key 和初始化向量 (IV) 的 DESCryptoServiceProvider,加密 inName指定的文件,并将加密结果输出到 outName 指定的
文件。
private static void EncryptData(String inName, String outName, byte[] desKey, byte[] desIV)
{
//Create the file streams to handle the input and output files.
FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
FileStream fout = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
fout.SetLength(0);
//Create variables to help with read and write.
byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
long rdlen =0; //This is the total number of bytes written.
long totlen = fin.Length; //This is the total length of the input file.
int len; //This is the number of bytes to be written at a time.
DES des = new DESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);
Console.WriteLine("Encrypting...");
//Read from the input file, then encrypt and write to the output file.
while(rdlen {
len = fin.Read(bin, 0, 100);
encStream.Write(bin, 0, len);
rdlen = rdlen + len;
Console.WriteLine("{0} bytes processed", rdlen);
}
encStream.Close();
fout.Close();
fin.Close();
}
[Visual Basic, C#] 可以相同的方法进行解密;使用 CreateDecryptor而不是 CreateEncryptor。必须使用加密该文件所用的同一 Key 和
IV 进行解密。
RC2CryptoServiceProvider 类
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
namespace RC2CryptoServiceProvider_Examples
{
class MyMainClass
{
public static void Main()
{
string original = "This is a much longer string of data than a public/private key algorithm will accept.";
string roundtrip;
ASCIIEncoding textConverter = new ASCIIEncoding();
RC2CryptoServiceProvider rc2CSP = new RC2CryptoServiceProvider();
byte[] fromEncrypt;
byte[] encrypted;
byte[] toEncrypt;
byte[] key;
byte[] IV;
Console.WriteLine("Effective key size is {0} bits.", rc2CSP.EffectiveKeySize);
//Create a new key and initialization vector.
rc2CSP.GenerateKey();
rc2CSP.GenerateIV();
//Get the key and IV.
key = rc2CSP.Key;
本文转自
http://blog.sina.com.cn/s/blog_3f33dac1010003zp.html
- 关于.NET加密技术
- 关于.NET加密技术
- .NET加密技术应用
- .net加密技术
- .NET加密技术指南
- .NET加密技术
- .NET加密技术概述
- 关于URL加密技术
- 关于MD5加密技术
- 关于加密技术
- 关于加密.NET
- Asp.Net 密码加密技术
- 关于.Net加密与解密
- ASP.NET加密技术的应用
- 安全第一:.NET加密技术指南(1)
- 安全第一:.NET加密技术指南(2)
- .NET中的加密与解密技术
- 微软.net加密技术简介[上]
- 判断文件夹是否存在
- LINQ
- pb筆記
- 斐波那契数列 PHP Implements
- pb筆記2
- 关于.NET加密技术
- 出现此问题的解决方法: unexpected end of file while looking for precompiled header directive
- 2007年7月最受关注的20篇技术文章
- 用vc++动态加载dll
- VBScript UBound 函数
- 如何将Oracle 如何将当前日期加一天、一分钟?
- 用Java实现ESB
- JavaScript的方法和技巧
- 对URL含有中文参数的转换