machinekey 생성하는 validationkey 와 decryptionkey 값 생성하는 방법
public class KeyGenerator
{
public string GenerateKey(int length, bool useUpperCase = true)
{
byte[] buffer = new byte[length];
var randomNumberGenerator = new RNGCryptoServiceProvider();
randomNumberGenerator.GetBytes(buffer);
return ToHexString(buffer, true);
}
private static string ToHexString(byte[] bytes, bool useUpperCase = false)
{
var hex = string.Concat(bytes.Select(b => b.ToString(useUpperCase ? "X2" : "x2")));
return hex;
}
}
var generator = new KeyGenerator();
/* 512 bits = 64 bytes (512 / 8) */
string validationKey = generator.GenerateKey(64);
/* 256 bits = 32 bytes (256 / 8) */
string decryptionKey = generator.GenerateKey(32);
<machinekey compatibilitymode="Framework45"
validation="HMACSHA256"
validationkey="YOURVALIDATIONKEYHERE"
decryption="AES"
decryptionkey="YOURDECRYPTIONKEYHERE" />
샘플(모르겠으면 그냥 아래꺼 쓰심~)
<system.web>
<machineKey validationKey="E4451576F51E0562D91A1748DF7AB3027FEF3C2CCAC46D756C833E1AF20C7BAEFFACF97C7081ADA4648918E0B56BF27D1699A6EB2D9B6967A562CAD14767F163"
decryptionKey="6159C46C9E288028ED26F5A65CED7317A83CB3485DE8C592" validation="HMACSHA256" decryption="AES" />