Visual C# .NET을 사용하여 폼 인증에서 사용할 키를 만드는 방법
http://support.microsoft.com/default.aspx?scid=312906
http://support.microsoft.com/default.aspx?scid=312906
using System;
using System.Text;
using System.Security.Cryptography;
namespace Crypto
{
public class KeyCreator
{
public static void Main(String[] args)
{
String[] commandLineArgs = System.Environment.GetCommandLineArgs();
string decryptionKey = CreateKey(System.Convert.ToInt32(commandLineArgs[1]));
string validationKey = CreateKey(System.Convert.ToInt32(commandLineArgs[2]));
Console.WriteLine("", 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();
}
}
}
'개발 > C# .NET' 카테고리의 다른 글
| [MVC] DropDownList에 Enum 바인딩 (0) | 2011.09.21 |
|---|---|
| [MVC] EnumDropDownList (0) | 2011.06.22 |
| C# 한글깨짐 처리 (1) | 2011.04.20 |