The title is a bit difficult. Please forgive me. Here I will explain...
Background:
The company often sends some Enewsletter, which contains some specific links. When a user clicks the link in the email, the customer will be taken to different pages based on the user's information, some customers are asked to fill out their forms, which have their basic information in advance at the beginning.
The customer may be from the original registered users of the company site, or from the company's information collected from other places. -- In addition, This is different from the general spam, but an invitation letter for a specific group.
Problem:
The faster the request is, the better. Therefore, the customer's email is placed directly in the Link. But how can we prevent customers or others from seeing or modifying it?
Implementation:
Ha! Fortunately, asp.net has a country called System. Security. Cryptography.
A group dedicated to encryption and decryption within this country...
Create a class for this requirement:
public static class SimpleSecurity{ private const string MyKey = "uptoyou"; static public string Decrypt(string myString, bool urlDecode) { TripleDESCryptoServiceProvider cryptDES3 = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider cryptMD5Hash = new MD5CryptoServiceProvider(); cryptDES3.Key = cryptMD5Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(MyKey)); cryptDES3.Mode = CipherMode.ECB; ICryptoTransform desdencrypt = cryptDES3.CreateDecryptor(); byte[] buff = Convert.FromBase64String(myString); return ASCIIEncoding.ASCII.GetString(desdencrypt.TransformFinalBlock(buff, 0, buff.Length)); } static public string Encrypt(string myString) { TripleDESCryptoServiceProvider cryptDES3 = new TripleDESCryptoServiceProvider(); MD5CryptoServiceProvider cryptMD5Hash = new MD5CryptoServiceProvider(); cryptDES3.Key = cryptMD5Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(MyKey)); cryptDES3.Mode = CipherMode.ECB; ICryptoTransform desdencrypt = cryptDES3.CreateEncryptor(); byte[] buff = ASCIIEncoding.ASCII.GetBytes(myString); return s = Convert.ToBase64String(desdencrypt.TransformFinalBlock(buff, 0, buff.Length)); }}
To Encrypt customers' emails and generate the desired url address, you can:
SimpleSecurity.Encrypt(email);
The generated string may be similar to: 6OpKSqWe57SAHBhmJJsF7Q % 3d % 3 dccc. Because the Key is in your hand, it is very unlikely that others will decrypt it.
Next, if you want to decrypt the email from the address requested by the customer page, you only need:
if (Request.QueryString["u"] != null) email = SimpleSecurity.Decrypt(Request.QueryString["u"]);
It is simple and safe. I hope you can reply to the post for discussion and follow up. You are welcome to come up with different ideas.