如何在ASPX中加密重置密码URL?

时间:2016-08-23 05:27:51

标签: asp.net encryption

我不是在问这个功能是如何编程的,我问的是如何加密密码重置的URL,并在aspx下使其成为临时的。什么是最好的加密方法,md5,base64或什么??

例如: mysite.com/account/resetpass.aspx?sg=2c9P8uK6VJlJ&mp=2c9VPKR4LnwEI

由于

1 个答案:

答案 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;
    }