我不是在问这个功能是如何编程的,我问的是如何加密密码重置的URL,并在aspx下使其成为临时的。什么是最好的加密方法,md5,base64或什么??
例如: mysite.com/account/resetpass.aspx?sg=2c9P8uK6VJlJ&mp=2c9VPKR4LnwEI
由于
答案 0 :(得分:0)
试试这样:
protected void Submit(object sender, EventArgs e)
{
string name = HttpUtility.UrlEncode(Encrypt(userName.Trim()));
string technology = HttpUtility.UrlEncode(Encrypt(password.Trim()));
Response.Redirect(string.Format("~/page.aspx?sg={0}&mp={1}", name, technology));
}
private string Encrypt(string MyText)
{
string EncryptionKey = "MAKV2SPBNI99212";
byte[] clearBytes = Encoding.Unicode.GetBytes(MyText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(clearBytes, 0, clearBytes.Length);
cs.Close();
}
MyText= Convert.ToBase64String(ms.ToArray());
}
}
return MyText;
}