This is an application that will generate a valid machineKey block with random, secure, hard-coded keys that you can paste inside the <system.web> in your web.config or machine.config file.
Hard-coded encryption and validation keys are needed if you have a web farm/web garden, if you use passwordFormat=Encrypted with ASP.NET 2.0’s Membership provider, or if you have certain ViewState issues. I discuss those reasons more in-depth in my blog posts about “Invalid Viewstate” errors and the ASP.NET Membership Encrypted passwordFormat, or you can also read my machineKey CodeProject article for more background information.
Below is a random set of keys, generated by this page. Go ahead and refresh this page to get a new set of keys.
ASP.NET 1.1 machineKey
<machineKey validationKey="20C7A8211EC2AEFC8CB3E1E66916FF0C4F9C468F5879F63A576F8392BC775090159BA208EE1A9F9F3CD9168DFB638DFC522035EC70A3FAF7FB1124343259676D" decryptionKey="9F6339D364A98CA8E7093DC86A9D6170A049123C924579E7" validation="SHA1" />
ASP.NET 2.0 machineKey
<machineKey validationKey="2750A9AFB19DC31BCA14D35876CA3A4597EE3D107F20326CA41D89202B9494097825CB2962F9271661BC21D12A1D46294270609B81426F708F19356664BDC515" decryptionKey="ABBC3F6E498E1A896238A84A100F6E4B86B29E45569755B0B447622B214035B1" validation="SHA1" decryption="AES" />
If you want, you can also use the code below so you can generate the keys yourself:
using System; using System.Text; using System.Security; using System.Security.Cryptography; private void Button1_Click(object sender, System.EventArgs e) { txtASPNET20.Text = getASPNET20machinekey(); txtASPNET11.Text = getASPNET11machinekey(); } public string getASPNET20machinekey() { StringBuilder aspnet20machinekey = new StringBuilder(); string key64byte = getRandomKey(64); string key32byte = getRandomKey(32); aspnet20machinekey.Append("\n"); return aspnet20machinekey.ToString(); } public string getASPNET11machinekey() { StringBuilder aspnet11machinekey = new StringBuilder(); string key64byte = getRandomKey(64); string key24byte = getRandomKey(24); aspnet11machinekey.Append(" \n"); return aspnet11machinekey.ToString(); } public string getRandomKey(int bytelength) { int len = bytelength * 2; byte[] buff = new byte[len / 2]; RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); rng.GetBytes(buff); StringBuilder sb = new StringBuilder(len); for (int i = 0; i < buff.Length; i++) sb.Append(string.Format("{0:X2}", buff[i])); return sb.ToString(); }