-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerate Machine Key.linq
35 lines (29 loc) · 1012 Bytes
/
Generate Machine Key.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<Query Kind="Program">
<Reference><RuntimeDirectory>\System.Security.dll</Reference>
<Namespace>System.Security.Cryptography</Namespace>
</Query>
void Main()
{
int decryptionKeySize = 24;
int validationKeySize = 64;
string[] commandLineArgs = System.Environment.GetCommandLineArgs();
string decryptionKey = CreateKey(decryptionKeySize);
string validationKey = CreateKey(validationKeySize);
Console.WriteLine("<machineKey\r\n\tvalidationKey=\"{0}\"\r\n\tdecryptionKey=\"{1}\"\r\n\tvalidation=\"SHA1\"/>", validationKey, decryptionKey);
}
static string CreateKey(int numBytes)
{
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
byte[] buff = new byte[numBytes];
rng.GetBytes(buff);
return BytesToHexString(buff);
}
static string BytesToHexString(byte[] bytes)
{
StringBuilder hexString = new StringBuilder(64);
for (int counter = 0; counter < bytes.Length; counter++)
{
hexString.Append(String.Format("{0:X2}", bytes[counter]));
}
return hexString.ToString();
}