Article ID: 313091 - Last Review: October 29, 2007 - Revision: 3.10 How to create keys by using Visual Basic .NET for use in Forms authentication
This article was previously published under Q313091 On This PageSUMMARY This article describes how to create keys to use for
encryption, decryption, and validation of Forms authentication cookie data. You
can use the keys that you create in this article for the validationKey and the decryptionKey attributes of the <machineKey> section in the <system.web> element in the Machine.config and the Web.config
files. RequirementsThe following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
Create the project
Write the code to hash a passwordThe code in this section reads two arguments that are passed from the command line:
Note The hexadecimal string that is created is twice the size of the value that is passed on the command line. For example, if you specify 24 bytes for a key, the resulting string is 48 bytes in length after the conversion. The valid values for decryptionKey is 8 or 24. This creates a 16 byte key for Data Encryption Standard (DES) or a 48 byte key for Triple DES, respectively. Valid values for validationKey are 20 to 64. This creates keys from 40 to 128 bytes in length after the conversion. The output from the code is an entire <machineKey> element that you can copy and paste into a Machine.config or a Web.config file.
Generate the hashesRun the application from a command prompt, and then pass in two integer values that are the size of the decryption and the validation keys. If you named the console application HashConfigVb.exe, type the following syntax at the command prompt in the Bin directory of the application:HashConfigVb.exe 24 64 The application should return output that is similar to the
following output:
<machineKey validationKey="08CE6B478DCE73..........E566D8AC5D1C045BA60"
decryptionKey="4252D6B2268.........67F451CE65D0F2ABE9BCD3A"
validation="SHA1"/>
Update the configuration file
TroubleshootingMake sure that the <machineKey> section has identical, explicit keys (that is, do not use the AutoGenerate option for attributes in the <machineKey> section) across the Web farm in the following scenarios:
REFERENCES
For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
308157
(http://support.microsoft.com/kb/308157/
)
How to implement forms-based authentication in your ASP.NET application by using Visual Basic .NET
306238
(http://support.microsoft.com/kb/306238/
)
How to implement role-based security with Forms-based authentication in your ASP.NET application by using Visual Basic .NET
306590
(http://support.microsoft.com/kb/306590/
)
INFO:
ASP.NET security overview
307626
(http://support.microsoft.com/kb/307626/
)
INFO:
ASP.NET configuration overview
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations
|





















Back to the top