'HMACSHA1 in Blazor
I have to call payment window in Blazor Server / client project with HMACSHA1. In asp.net I would have done it like this:
<body onload="document.form1.submit()">
<form name="form1" method="post" action="https://onpay.io/window/v3/" accept-charset="UTF-8">
<input type="hidden" name="onpay_gatewayid" value="5880726">
<input type="hidden" name="onpay_currency" value="EUR">
<input type="hidden" name="onpay_amount" value="<%= onpay_amount %>">
<input type="hidden" name="onpay_reference" value="<%= onpay_reference %>">
<input type="hidden" name="onpay_hmac_sha1" value="<%= onpay_hmac_sha1 %>">
<input type="hidden" name="onpay_accepturl" value="ecample.com/defaultPayment.aspx">
<%--<input type="submit" name="unrelated_param" value="Start payment of 120.00 DKK">--%>
Code behind:
var secret = "xxx";
var formParams = new Dictionary<string, string>{
{"onpay_gatewayid", "xxx"},
{"onpay_currency", "EUR"},
{"onpay_amount", onpay_amount},
{"onpay_reference", onpay_reference},
{"onpay_accepturl", "xxx.com/payment.aspx"}};
var onpayParams = formParams
.Where(x => x.Key.StartsWith("onpay_"))
.Where(x => x.Key != "onpay_hmac_sha1")
.OrderBy(x => x.Key)
.ToArray();
var queryString = string.Join("&", onpayParams.Select(x => HttpUtility.UrlEncode(x.Key) + "=" + HttpUtility.UrlEncode(x.Value))).ToLower();
var hashString = "";
using (var sha1 = new HMACSHA1(Encoding.UTF8.GetBytes(secret)))
{
var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(queryString));
hashString = string.Join("", hash.Select(x => x.ToString("x2")));
onpay_hmac_sha1 = hashString;
}
But I cant do it in a razor page, while it can't compile HMACSHA1. Any suggestions..?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
