Пример #1
0
        public void HMACMD5_GetStringHMAC_Test()
        {
            var source       = "zero1000";
            var hmacMd5Value = HMACUtil.GetHex16StringHMACMD5(source, "111111");

            Assert.Equal("fd6685a35748328b6306021e5f69cbd6", hmacMd5Value.ToLower());

            var stringBase64HmacMd5 = HMACUtil.GetBase64StringHMACMD5(source, "111111");

            Assert.Equal("/WaFo1dIMotjBgIeX2nL1g==", stringBase64HmacMd5);
        }
Пример #2
0
        public void HMACSHA1_GetStringHMAC_Test()
        {
            var source        = "helloworld";
            var hmacSha1Value = HMACUtil.GetHex16StringHMACSHA1(source, "12345678");

            Assert.Equal("0ca0559b0a2c77bd91619fa6cec9044f5e567a56", hmacSha1Value.ToLower());

            var stringBase64HmacSha1 = HMACUtil.GetBase64StringHMACSHA1(source, "111111");

            Assert.Equal("LY9OPidfBXHYmNJQ7ht4I49xYMU=", stringBase64HmacSha1);
        }
Пример #3
0
        public void HMACSHA256_GetStringHMAC_Test()
        {
            var source          = "zero1000";
            var hmacSha256Value = HMACUtil.GetHex16StringHMACSHA256(source, "111111");

            Assert.Equal("3885f54d0684044c1d5a7398346219b08ff9a9e3fe127cb7d3986516f6389d1e", hmacSha256Value.ToLower());

            var stringBase64HmacSha256 = HMACUtil.GetBase64StringHMACSHA256(source, "111111");

            Assert.Equal("OIX1TQaEBEwdWnOYNGIZsI/5qeP+Eny305hlFvY4nR4=", stringBase64HmacSha256);
        }
Пример #4
0
        public HttpResponseMessage Post(Report data)
        {
            try
            {
                if (Request != null && Request.Headers.Contains("HMAC"))//Validate for HMAC Value recieved from the Certify.me Webhook
                {
                    var key = Request.Headers.GetValues("HMAC").First();

                    if (!HMACUtil.CompareHMAC256(data.uid, ConfigurationManager.AppSettings["HMACKey"], key))//HMAC value is created based on the Key in the config , should match the one provided on the portal
                    {
                        return(ReturnUnAuthorized());
                    }

                    //IF AUTHORIZED PROCESS DATA.
                    //WRITE RECIEVED DATA TO A FILE.
                    var time = DateTime.Now.ToString("yyyyMMddhhmmssff");
                    var path =
                        HttpContext.Current.Server.MapPath($"~/App_Data/{time}post.txt");
                    File.WriteAllText(path, JsonConvert.SerializeObject(data));
                    var responseMessage = new HttpResponseMessage(HttpStatusCode.OK) //SEND STATUS 200 MESSAGE
                    {
                        Content = new StringContent("Data Received"),
                    };
                    return(responseMessage);
                }
                else
                {
                    return(ReturnUnAuthorized()); //ERROR 401
                }
            }
            catch (Exception ex)
            {
                //log your exception
                return(InternalServerError()); //ERROR 500
            }
        }