var apiKey = "apikey";
var secretKey = "secretkey";
// Generate a new globally unique identifier for the salt
var salt = System.Guid.NewGuid().ToString();
// Initialize the keyed hash object using the secret key as the key
HMACSHA256 hashObject = new HMACSHA256(Encoding.UTF8.GetBytes(secretKey));
// Computes the signature by hashing the salt with the secret key as the key
var signature = hashObject.ComputeHash(Encoding.UTF8.GetBytes(salt));
// Base 64 Encode
var encodedSignature = Convert.ToBase64String(signature);
// URLEncode
encodedSignature = System.Web.HttpUtility.UrlEncode(encodedSignature);
/*
* Following code for test an method will be inlined by JIT or not
* Tested on Framework 4.5, Win8 x64
*
* http://blogs.msdn.com/b/ericgu/archive/2004/01/29/64717.aspx
* http://blogs.microsoft.co.il/blogs/sasha/archive/2012/01/20/aggressive-inlining-in-the-clr-4-5-jit.aspx
*/
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Fa(1)); // Main
Console.WriteLine(Fb(1)); // Fb
Console.WriteLine(Fc(1)); // Main
Console.WriteLine(Fd(1)); // Main
Console.WriteLine(Fe(1)); // Fe if Platform target is x86, Main if x64
Console.WriteLine(Ff(1)); // Ff
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static string Fa(int a)
{
var s = a.ToString();
var b = uint.Parse(s);
var c = (a + b) / 2;
var ss = c.ToString();
var d = int.Parse(ss);
return new StackFrame().GetMethod().Name;
}
static string Fb(int a)
{
var s = a.ToString();
var b = uint.Parse(s);
var c = (a + b) / 2;
var ss = c.ToString();
var d = int.Parse(ss);
return new StackFrame().GetMethod().Name;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static string Fc(int a)
{
return new StackFrame().GetMethod().Name;
}
static string Fd(int a)
{
return new StackFrame().GetMethod().Name;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static string Fe(int a)
{
a += 1;
return new StackFrame().GetMethod().Name;
}
static string Ff(int a)
{
a += 1;
return new StackFrame().GetMethod().Name;
}
}
/// <summary>
/// Redirect the current request back to the current page = full page reload
/// </summary>
public static void RedirectSelf(this HttpResponse response)
{
response.Redirect(HttpContext.Current.Request.RawUrl);
}
public sealed class Remote<T> where T : MarshalByRefObject
{
private readonly AppDomain domain;
private readonly T remoteObject;
private Remote(AppDomain domain, T remoteObject)
{
this.domain = domain;
this.remoteObject = remoteObject;
}
public T RemoteObject
{
get { return remoteObject; }
}
public AppDomain Domain
{
get { return domain; }
}
public static Remote<T> CreateProxy(AppDomain domain, params object[] constructorArgs)
{
if (domain == null)
{
throw new ArgumentNullException("domain");
}
var type = typeof(T);
var proxy = (T)domain.CreateInstanceAndUnwrap(
type.Assembly.FullName,
type.FullName,
false,
BindingFlags.CreateInstance,
null,
constructorArgs,
null,
null);
return new Remote<T>(domain, proxy);
}
}
public static void Shuffle<T>(this T[] array, Random random)
{
int n = array.Length;
while (n > 1)
{
int k = random.Next(n--);
T temp = array[n];
array[n] = array[k];
array[k] = temp;
}
}
public static void Shuffle<T>(this IList<T> collection, Random random = null)
{
random = random ?? new Random();
int n = collection.Count();
while (n > 1)
{
int k = random.Next(n--);
T temp = collection[n];
collection[n] = collection[k];
collection[k] = temp;
}
}