Skip to main content

Built and signed on GitHub Actions

Crypto utils for import/export/gen ec keys

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 months ago (0.3.1)

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.

WebCrypto keys utilities

JSR CI

This library provides a set of functions for generating, importing, and exporting cryptographic keys and key pairs

Key Features

  • Import and export keys in different formats such as hex, raw, and jwk
  • Algorithm Support: Ed25519, P-256, P-384, P-521, and X25519

Install

// deno add jsr:@maks11060/crypto
import {generateKeyPair} from '@maks11060/crypto'

// or
import {generateKeyPair} from 'jsr:@maks11060/crypto'

Usage

import {exportKey, generateKeyPair, importKey, importKeyPair} from '@maks11060/crypto'

const keys = await generateKeyPair('Ed25519')
keys.privateKey // CryptoKey
keys.publicKey // CryptoKey

// export key pair
const {privateKey, publicKey} = await exportKey('hex', keys)
console.log(privateKey) // e6cc65db53dcdce37d095c5bd792a5114e8ca575190979dfaea1afa6da1daef9
console.log(publicKey) // b504196a380c1dcb0526c88df4f947b8d8e32f3e7a5ac57d852f439fc4fc80bc

// export single key
const privateKey_2 = await exportKey('hex', keys.privateKey)
const publicKey_2 = await exportKey('hex', keys.publicKey)
console.log(privateKey_2) // e6cc65db53dcdce37d095c5bd792a5114e8ca575190979dfaea1afa6da1daef9
console.log(publicKey_2) // b504196a380c1dcb0526c88df4f947b8d8e32f3e7a5ac57d852f439fc4fc80bc

// import private key
await importKey('hex', {alg: 'Ed25519', publicKey, privateKey})

// import public key
await importKey('hex', {alg: 'Ed25519', publicKey})

// import key pair
await importKeyPair('hex', {alg: 'Ed25519', publicKey, privateKey})

Algorithms

Algorithm generateKeyPair exportKey importKey
Ed25519
X25519
P-256, ES256
P-384, ES384
P-521, ES512 ✔ 1* ✔ 1*
  1. Deno is not supported
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@maks11060/crypto

Import symbol

import * as crypto from "@maks11060/crypto";

---- OR ----

Import directly with a jsr specifier

import * as crypto from "jsr:@maks11060/crypto";

Add Package

npx jsr add @maks11060/crypto

Import symbol

import * as crypto from "@maks11060/crypto";

Add Package

yarn dlx jsr add @maks11060/crypto

Import symbol

import * as crypto from "@maks11060/crypto";

Add Package

pnpm dlx jsr add @maks11060/crypto

Import symbol

import * as crypto from "@maks11060/crypto";

Add Package

bunx jsr add @maks11060/crypto

Import symbol

import * as crypto from "@maks11060/crypto";