Code samples
WebSub HMAC verification
C#
using System;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
public class Program
{
public static void Main()
{
Encoding utf8 = Encoding.UTF8;
String client_secret = "supersecret";
HMACSHA256 hmac_new_content = new HMACSHA256(utf8.GetBytes(client_secret));
String http_body = "{.....}";
Byte[] new_content_sig = hmac_new_content.ComputeHash(utf8.GetBytes(http_body));
Console.WriteLine(BitConverter.ToString(new_content_sig).Replace("-", ""));
}
}
Go
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"fmt"
)
func verificationNewContent() {
secret := "supersecret"
hm := hmac.New(sha256.New, []byte(secret))
httpBody := `{....}`
_, err := hm.Write([]byte(httpBody))
if err != nil {
fmt.Println(err)
}
hash := hex.EncodeToString(hm.Sum(nil))
fmt.Println(hash)
}
Last updated
Was this helpful?