Code Explainers

Code explainers tagged #hmac

java
public final class HmacJwt {
 
    private static final ObjectMapper MAPPER = new ObjectMapper();
    private static final Base64.Encoder ENCODER = Base64.getUrlEncoder().withoutPadding();

How HMAC-signed JWTs are created and verified

jwt hmac cryptography
Intermediate 9 steps
python
import base64
import hashlib
import hmac
import os

How TOTP two-factor codes work

totp hmac authentication
Intermediate 7 steps
ruby
require "openssl"
require "json"
require "base64"
 

Building signed session tokens in Ruby

hmac authentication cryptography
Intermediate 8 steps
go
package security
 
import (
	"crypto/hmac"

Signing and verifying payloads with HMAC in Go

hmac cryptography authentication
Intermediate 5 steps
php
<?php
 
namespace App\Http\Middleware;
 

Verifying GitHub webhook signatures in Laravel

middleware hmac webhooks
Intermediate 5 steps
python
import base64
import hashlib
import hmac
import json

Building signed expiring tokens with HMAC

hmac authentication base64
Intermediate 7 steps
php
<?php
 
namespace App\Support;
 

How TOTP codes are generated in PHP

totp hmac two-factor-auth
Advanced 7 steps
php
<?php
 
namespace App\Http\Middleware;
 

Verifying webhook signatures in Laravel

hmac middleware webhooks
Intermediate 7 steps
ruby
require "openssl"
require "base64"
 
module WebhookSignature

Signing and verifying webhooks in Ruby

hmac cryptography webhooks
Intermediate 7 steps
php
<?php
 
namespace App\Services;
 

Building signed, expiring download URLs in PHP in Laravel

hmac url-signing authentication
Intermediate 7 steps
go
package middleware
 
import (
	"bytes"

Verifying webhook HMAC signatures in Gin

hmac middleware webhooks
Intermediate 7 steps
rust
use axum::{
    body::Bytes,
    extract::State,
    http::{HeaderMap, StatusCode},

Verifying Stripe webhook signatures in Axum

hmac webhooks constant-time-comparison
Intermediate 8 steps
go
package webhooks
 
import (
	"crypto/hmac"

Verifying GitHub webhooks in Gin

hmac webhooks middleware
Intermediate 6 steps
python
import hashlib
import hmac
import os
 

Verifying signed payment webhooks in Flask

hmac webhooks signature verification
Intermediate 7 steps
php
<?php
 
function verifyJwt(string $token, string $secret): array
{

Verifying an HS256 JWT in PHP

jwt hmac authentication
Intermediate 9 steps