Last active
August 29, 2015 14:08
-
-
Save NikolayIT/9fbd8a06571475680e59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MyWebApp | |
{ | |
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using System.Web.Configuration; | |
using System.Web.Mvc; | |
public class SystemController : Controller | |
{ | |
public ActionResult GetMachineKeyConfiguration() | |
{ | |
var section = (MachineKeySection)ConfigurationManager.GetSection("system.web/machineKey"); | |
var flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty; | |
Func<string, byte[]> propertyReader = | |
name => (byte[])section.GetType().GetProperty(name, flags).GetValue(section, null); | |
var decryptionKey = ConvertToHex(propertyReader("DecryptionKeyInternal")); | |
var validationKey = ConvertToHex(propertyReader("ValidationKeyInternal")); | |
var output = new StringBuilder(); | |
output.AppendLine(section.Validation.ToString()); | |
output.AppendLine(validationKey); | |
output.AppendLine(section.Decryption); | |
output.AppendLine(decryptionKey); | |
return this.Content(output.ToString()); | |
} | |
private static string ConvertToHex(IEnumerable<byte> binary) | |
{ | |
return binary.Aggregate(new StringBuilder(), (acc, c) => acc.AppendFormat("{0:x2}", c), acc => acc.ToString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment