Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rdeak/jwe
JWE with compression
https://github.com/rdeak/jwe
jwe
Last synced: about 1 month ago
JSON representation
JWE with compression
- Host: GitHub
- URL: https://github.com/rdeak/jwe
- Owner: rdeak
- License: mit
- Created: 2024-01-08T09:04:48.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-01-15T15:47:55.000Z (11 months ago)
- Last Synced: 2024-05-15T21:05:14.762Z (7 months ago)
- Topics: jwe
- Language: TypeScript
- Homepage:
- Size: 187 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JWE
[![npm version](https://img.shields.io/npm/v/@rdeak/jwe/latest.svg)](https://www.npmjs.com/package/@rdeak/jwe)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/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](https://github.com/panva/jose) library.
## Installation
```bash
npm install @rdeak/jwe
```or
```bash
npm install https://github.com/rdeak/jwe
```## Usage
```javascript
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
| Name | Type |
| :-------- | :-------- |
| `secret` | `string` |
| `options` | `Options` |```typescript
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;
/***
* @deprecated https://www.rfc-editor.org/rfc/rfc8725#name-avoid-compression-of-encryp
*/
compression?: Compression;
};
```### encrypt
▸ **encrypt**(`payload`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>
Encrypts and resolves the value of the Compact JWE string.
#### Parameters
| Name | Type |
| :-------- | :------------------------ |
| `payload` | `Record` |#### Returns
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`>
### decrypt
```javascript
decrypt("jwe token....", "0123456789123456");
```▸ **decrypt**(`jweToken`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`string`\>
Decrypts a Compact JWE into object.
#### Parameters
| Name | Type |
| :--------- | :------- |
| `jweToken` | `string` |#### Returns
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`Record`>
## License
This project is licensed under the terms of the MIT license.