@adorsys/jwe-codec

Codec to encrypt any javascript value into a JsonWebEncryption (JWE)

Usage no npm install needed!

<script type="module">
  import adorsysJweCodec from 'https://cdn.skypack.dev/@adorsys/jwe-codec';
</script>

README

:closed_lock_with_key: jwe-codec :closed_lock_with_key:

Travis Coveralls npm npm Conventional Commits JavaScript Style Guide styled with prettier NpmLicense

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

Installation

npm install @adorsys/jwe-codec

Usage

const jwe = require('@adorsys/jwe-codec')

const key = {
  kty: 'oct',
    alg: 'A256GCM',
    use: 'enc',
    k: '123456789abcdefghijklmnopqrstuvwxyz12345678'
}

...

with async/await

...

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

...

jwe(key).then(codec => {
    codec.encrypt(42).then(cipher => {
        codec.decrypt(cipher).then(answer => {
            console.log(answer) // 42
        })
    })
})

Credits

Made with :heart: by radzom and all these wonderful contributors (emoji key):


Francis Pouatcha
🤔

jkroepke
💻🐛

This project follows the all-contributors specification. Contributions of any kind are welcome!