private static byte[] F(string password, Salt salt, int derivationIterations) { HMAC hmacsha512 = New <HMACSHA512>().Initialize(new SymmetricKey(new UTF8Encoding(false).GetBytes(password))); hmacsha512.TransformBlock(salt.GetBytes(), 0, salt.Length, null, 0); byte[] iBytes = 1.GetBigEndianBytes(); hmacsha512.TransformBlock(iBytes, 0, iBytes.Length, null, 0); hmacsha512.TransformFinalBlock(_empty, 0, 0); byte[] u = hmacsha512.Hash(); byte[] un = u; for (int c = 2; c <= derivationIterations; ++c) { hmacsha512.Initialize(); hmacsha512.TransformBlock(u, 0, u.Length, null, 0); hmacsha512.TransformFinalBlock(_empty, 0, 0); u = hmacsha512.Hash(); for (int i = 0; i < u.Length; i++) { un[i] ^= u[i]; } } return(un); }
internal static Default.Container Context() { string LogMsg = MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().ToString() + " :: "; try { var container = new Default.Container(new Uri(serviceURI)); container.Timeout = serviceTimeout; container.BuildingRequest += (sender, eventArgs) => { //attach header information required to use ApiKey var hmac = new HMAC() { TimeStamp = DateTime.UtcNow.ToString(), Uri = eventArgs.RequestUri.ToString(), Method = eventArgs.Method.ToString(), AppID = appID, ApiKey = apiKey }; hmac.SetNonce(); eventArgs.Headers.Add("HMAC", hmac.BuildHeader()); eventArgs.Headers.Add("Hash", hmac.Hash()); }; return(container); } catch (Exception ex) { NLogWriter.LogMessage(LogType.Error, LogMsg + "Exception calling Flotation Device Service Application :: " + ex.ToString()); throw; } }