This module provides a way to create HMAC (Hash-based Message Authentication Code) signatures encoded as hex strings.
Example 1
import { createHmac, generateHmacSecret } from "./mod.ts"; const secret = await generateHmacSecret("SHA-384"); const hmac = createHmac(secret); // or createHmac("yourSecret") const message = "hello, world!"; const signedMessage = await hmac.sign(message); console.log(await hmac.verify(signedMessage)); // true // keep signature seperate const signature = hmac.signature(message); console.log(await hmac.verify(message, signature)); // true console.log(await hmac.verify("bye, world!", signature)); // false
The createHmac
function creates an HMAC signer with a given secret and a hash algorithm.
The generateHmacSecret
helper function generates a secure secret for a given hash algorithm.
The Hmac
interface represents an HMAC signer.
The SecureHashingAlgorithm
represents one of the three secure hashing algorithms native to the Web Crypto API.
Add Package
deno add jsr:@simple/hmac
Import symbol
import * as hmac from "@simple/hmac";
---- OR ----
Import directly with a jsr specifier
import * as hmac from "jsr:@simple/hmac";
Add Package
npx jsr add @simple/hmac
Import symbol
import * as hmac from "@simple/hmac";
Add Package
yarn dlx jsr add @simple/hmac
Import symbol
import * as hmac from "@simple/hmac";
Add Package
pnpm dlx jsr add @simple/hmac
Import symbol
import * as hmac from "@simple/hmac";
Add Package
bunx jsr add @simple/hmac
Import symbol
import * as hmac from "@simple/hmac";