public void HMACSHATest() { string str = "Hello world!"; string key = "123456"; string[] types = Enum.GetNames(typeof(HMACAlgorithmTypes)); foreach (var item in types) { #if !NFX if (item == "RIPEMD160") { continue; } #endif Console.WriteLine($"HMACAlgorithmType: {item}"); HashResult result = HMAC.Encrypt((HMACAlgorithmTypes)Enum.Parse(typeof(HMACAlgorithmTypes), item), str, key); Type type = result.GetType(); var props = type.GetProperties(); foreach (var prop in props) { if (prop.PropertyType == typeof(string)) { Console.WriteLine($"{prop.Name}:{prop.GetValue(result, null)}"); } } Console.WriteLine(); } }
public IActionResult HMACEncrypt([FromBody] HMACViewModel viewModel) { HMAC hmac = new HMAC(viewModel.HashType); string encrypted = ""; try { encrypted = hmac.Encrypt(viewModel.Message, viewModel.Key); } catch (Exception e) { return(BadRequest(new { Result = false, Message = e.Message })); } return(Json(encrypted)); }