using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using system.security.cryptography;
using system.text;
public class encryptpassword
/// /// 加密密碼
///
///
///
///
public static string encryptpwd(string pwdstring, string salt)
byte bytes = encoding.unicode.getbytes(salt.tolower().trim() + pwdstring.trim());
return bitconverter.tostring(((hashalgorithm)cryptoconfig.createfromname("sha1")).computehash(bytes));
}}using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.security.cryptography;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using system.io;
using system.text;
/// /// summary description for desencrypt
///
public class desencrypt
/// /// 設定加密金鑰
///
public string encryptkey
set}
/// /// 要加密字元的編碼模式
///
public encoding encodingmode
set
}/// /// 加密字串並返回加密後的結果
///
///
///
public string encryptstring(string str)
}
1.原理:每次產生乙個隨機字串作為密匙,使用者輸入乙個密碼,密碼經過密匙加密得到乙個字串存放在資料庫中...當需要驗證密碼時,要先得到密匙才能驗證.
datatable dt = wytweb.userdao.userlogin(username);
if (dt.rows.count == 0)
datarow row = dt.rows[0];
//得到密匙
string salt = row["salt"].tostring();
//驗證密碼是否正確
if (encryptpassword.encryptpwd(password, salt) == row["password"].tostring())
int userid = loginuser_id;
//獲得密匙
string salt = encryptpassword.createsalt();
//得到經過加密後的"密碼"
string password = encryptpassword.encryptpwd(txtpassword.text.trim(), salt);
//修改原資料
int result = wytweb.userdao.editpassword(userid, password, salt);
if (result > 0)
else
DES加密解密
using system using system.drawing using system.collections using system.componentmodel using system.windows.forms using system.data using system.io us...
DES加密解密
加密類 date 2012 04 23 pm.public class encrypt private encrypt 建立加密類物件.public static encrypt createcryptoserviceprovider des加密.待加密字串.加密金鑰.8位 public strin...
DES加密解密
自己寫的des加密解密類,加密後生成base64字串,並去除 字元。加密後替換掉 這樣加密後的字串可以作為url引數傳遞。using system using system.io using system.security.cryptography using system.text namespa...