You can use encryption and decryption algorithm (cryptography) to achieve your goal like this...
public class CryptoEngine
{
private static CryptoEngine _instance;
private CryptoEngine() { }
public static CryptoEngine Instance
{
get
{
if (_instance == null)
_instance = new CryptoEngine();
return _instance;
}
}
static readonly string PasswordHash = "@dM!nCo$";
static readonly string SaltKey = "AdMinCos";
static readonly string VIKey = "Polar!s@dM!nCoN$";
public string Encrypt(string plainText)
{
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.Zeros };
var encryptor = symmetricKey.CreateEncryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));
byte[] cipherTextBytes;
using (var memoryStream = new MemoryStream())
{
using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
{
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
cipherTextBytes = memoryStream.ToArray();
cryptoStream.Close();
}
memoryStream.Close();
}
return Convert.ToBase64String(cipherTextBytes);
}
public string Decrypt(string encryptedText)
{
encryptedText = encryptedText.Trim();
if (encryptedText.Contains(" "))
{
encryptedText = encryptedText.Replace(" ", "+");
}
byte[] cipherTextBytes = Convert.FromBase64String(encryptedText);
byte[] keyBytes = new Rfc2898DeriveBytes(PasswordHash, Encoding.ASCII.GetBytes(SaltKey)).GetBytes(256 / 8);
var symmetricKey = new RijndaelManaged() { Mode = CipherMode.CBC, Padding = PaddingMode.None };
var decryptor = symmetricKey.CreateDecryptor(keyBytes, Encoding.ASCII.GetBytes(VIKey));
var memoryStream = new MemoryStream(cipherTextBytes);
var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
byte[] plainTextBytes = new byte[cipherTextBytes.Length];
int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
memoryStream.Close();
cryptoStream.Close();
return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount).TrimEnd("\0".ToCharArray());
}
}
and use it like this...
"/Store/Details?id="+CryptoEngine.Instance.Encrypt(toode))
and in your action you can decrypt it as like this...
public ActionResult Details(string id)
{
string _id = CryptoEngine.Instance.Decrypt(id);
.......
You can set your PasswordHash, SaltKey and VIKey
i think this is what you want.
You can check more about cryptography
Reference