https://github.com/adorsys/jwe-codec
Simple Encrypting/Decrypting using JWE
https://github.com/adorsys/jwe-codec
codec decryption encryption jwe
Last synced: about 1 month ago
JSON representation
Simple Encrypting/Decrypting using JWE
- Host: GitHub
- URL: https://github.com/adorsys/jwe-codec
- Owner: adorsys
- License: mit
- Created: 2018-09-21T12:30:39.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T13:17:27.000Z (almost 3 years ago)
- Last Synced: 2025-08-08T13:14:12.302Z (4 months ago)
- Topics: codec, decryption, encryption, jwe
- Language: JavaScript
- Homepage:
- Size: 1.5 MB
- Stars: 0
- Watchers: 5
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :closed_lock_with_key: jwe-codec :closed_lock_with_key:
[](#contributors-)
[](https://travis-ci.org/adorsys/jwe-codec)
[](https://coveralls.io/github/adorsys/jwe-codec)
[](https://www.npmjs.com/package/@adorsys/jwe-codec)
[](https://www.npmjs.com/package/@adorsys/jwe-codec)
[](https://conventionalcommits.org)
[](https://standardjs.com)
[](https://github.com/prettier/prettier#readme)
[](https://github.com/adorsys/jwe-codec/blob/master/LICENSE)
A library for encrypting/decrypting any JavaScript value as JsonWebEncryption (JWE)
### Features
- Promise based interface
- Encrypting/Decrypting anything from (number, string, boolean, array, date, regex, buffer, object)
- TypeScript support
- support for symetric JsonWebKeys { kty: 'oct' }
- supported algorithms 'A256KW', 'A256GCM', 'A256GCMKW', 'A128CBC-HS256'
- Continous integration with [Travis](https://travis-ci.org/adorsys/jwe-codec)
### Installation
```bash
npm install @adorsys/jwe-codec
```
### Usage
```js
const jwe = require('@adorsys/jwe-codec')
const key = {
kty: 'oct',
alg: 'A256GCM',
use: 'enc',
k: '123456789abcdefghijklmnopqrstuvwxyz12345678'
}
...
```
#### with async/await
```js
...
;(async () => {
const codec = await jwe(key)
const cipher = await codec.encrypt(42)
// => eyJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiZGlyIiwia2lkIjoialpESEVqN0ZhR3N5OHNUSUZLRWlnejB4TjFEVWlBZWp0S1ZNcEl2Z3dqOCJ9..lipFQHmBiBhsTRqE.4rLjRCOj7JZIKOpToIhOp8cJgvfNWl4Yo__VnkO7yRIYjrCLdGRl5fcR.9S_DwYmkpdLap1yyYYq44A
const answer = await codec.decrypt(cipher)
// => 42
})()
```
#### with Promises
```js
...
jwe(key).then(codec => {
codec.encrypt(42).then(cipher => {
codec.decrypt(cipher).then(answer => {
console.log(answer) // 42
})
})
})
```
## Credits
Made with :heart: by [radzom](https://github.com/radzom) and all these wonderful contributors ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

Francis Pouatcha
🤔

Jan-Otto Kröpke
🚧 🚇 🐛
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind are welcome!