Skip to main content

latest
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
82%
Published
a year ago (0.0.2)

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

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 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";