Skip to content

Instantly share code, notes, and snippets.

@NikolayIT
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NikolayIT/9fbd8a06571475680e59 to your computer and use it in GitHub Desktop.
Save NikolayIT/9fbd8a06571475680e59 to your computer and use it in GitHub Desktop.
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