Skip to main content

latest
Works with
JSR Score
82%
Published
3 months ago (0.0.2)

This module provides a way to create HMAC (Hash-based Message Authentication Code) signatures encoded as hex strings.

Examples

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 @simple/hmac

Import symbol

import * as mod from "@simple/hmac";

Add Package

npx jsr add @simple/hmac

Import symbol

import * as mod from "@simple/hmac";

Add Package

yarn dlx jsr add @simple/hmac

Import symbol

import * as mod from "@simple/hmac";

Add Package

pnpm dlx jsr add @simple/hmac

Import symbol

import * as mod from "@simple/hmac";

Add Package

bunx jsr add @simple/hmac

Import symbol

import * as mod from "@simple/hmac";