New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@rdeak/jwe

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rdeak/jwe

JWE with compression

latest
Source
npmnpm
Version
2.0.2
Version published
Maintainers
1
Created
Source

JWE

npm version License: MIT

This repo exposes functions for encrypting JSON payloads, and decrypting JWE tokens into JSON from Node.js.

By default, dir algorithm is used for encryption of CEK, and A128GCM for encryption of a payload.

Underhood it uses jose library.

Installation

npm install @rdeak/jwe

or

npm install https://github.com/rdeak/jwe

Usage

import { encrypt, decrypt } from "@rdeak/jwe";

const jwe = JWE("0123456789123456");

const jweToken = await jwe.encrypt({ name: "John Doe" });
console.log("JWE:", jweToken);

const payload = await jwe.decrypt(jweToken);
console.table(payload);

API Documentation

JWE

Create handler for encrypting and decrypting JWE tokens.

Parameters

NameType
secretstring
optionsOptions
type Options = {
  /***
   * cryptographic algorithm used to encrypt CEK
   */
  alg?: string;
  /***
   * cryptographic algorithm used to encrypt payload
   */
  enc?: string;
  /***
   * default content is converted to JSON
   */
  transform?: Transform<PAYLOAD>;
  /***
   * @deprecated https://www.rfc-editor.org/rfc/rfc8725#name-avoid-compression-of-encryp
   */
  compression?: Compression;
};

encrypt

encrypt(payload): Promise<string>

Encrypts and resolves the value of the Compact JWE string.

Parameters

NameType
payloadRecord<string, unknown>

Returns

Promise<string>

decrypt

decrypt("jwe token....", "0123456789123456");

decrypt(jweToken): Promise<string>

Decrypts a Compact JWE into object.

Parameters

NameType
jweTokenstring

Returns

Promise<Record<string, unknown>>

License

This project is licensed under the terms of the MIT license.

Keywords

jwe

FAQs

Package last updated on 27 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts