개발/C# .NET
자동 생성된 Machinekey 읽기
xwing
2011. 4. 15. 11:00
Web.Config에 따로 설정을 하면 machinekey를 읽을 필요는 없겠지만서도..
나처럼 필요한 경우가 생길지도 몰라 구글링을 통해서 얻은 정보를 공유한다.
출처 :
http://aspnetresources.com/blog/how_to_read_auto_generated_machinekey
나처럼 필요한 경우가 생길지도 몰라 구글링을 통해서 얻은 정보를 공유한다.
protected void Page_Load (object sender, EventArgs e) { MachineKeySection section = (MachineKeySection) ConfigurationManager.GetSection ("system.web/machineKey"); BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty; FuncpropertyReader = name => (byte[]) section .GetType () .GetProperty (name, flags) .GetValue (section, null); string key = ConvertToHex ( propertyReader ("DecryptionKeyInternal")); string iv = ConvertToHex ( propertyReader ("ValidationKeyInternal")); } private string ConvertToHex (byte[] binary) { return binary.Aggregate ( new StringBuilder (), (acc, c) => acc.AppendFormat ("{0:x2}", c), acc => acc.ToString()); }// 뒤에요거 왜붙지? =>
출처 :
http://aspnetresources.com/blog/how_to_read_auto_generated_machinekey