-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from swlodarski-sumoheavy/feature/SP-1022
SP-1022 - C# Kiosk Demo: Add HMAC verification
- Loading branch information
Showing
6 changed files
with
143 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ioskDemoDotnet/Src/Invoice/Infrastructure/Features/Tasks/UpdateInvoice/WebhookVerifier.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2023 BitPay. | ||
// All rights reserved. | ||
|
||
using System; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace CsharpKioskDemoDotnet.Invoice.Infrastructure.Features.Tasks.UpdateInvoice; | ||
|
||
public class WebhookVerifier | ||
{ | ||
public bool Verify(string signingKey, string sigHeader, string webhookBody) | ||
{ | ||
ArgumentNullException.ThrowIfNull(signingKey); | ||
ArgumentNullException.ThrowIfNull(sigHeader); | ||
ArgumentNullException.ThrowIfNull(webhookBody); | ||
|
||
using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(signingKey)); | ||
byte[] signatureBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(webhookBody)); | ||
string calculated = Convert.ToBase64String(signatureBytes); | ||
bool match = sigHeader.Equals(calculated, StringComparison.Ordinal); | ||
|
||
return match; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters