A library for encrypting/decrypting any JavaScript value as JsonWebEncryption (JWE)
- 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
npm install @adorsys/jwe-codec
const jwe = require('@adorsys/jwe-codec')
const key = {
kty: 'oct',
alg: 'A256GCM',
use: 'enc',
k: '123456789abcdefghijklmnopqrstuvwxyz12345678'
}
...
...
;(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
})()
...
jwe(key).then(codec => {
codec.encrypt(42).then(cipher => {
codec.decrypt(cipher).then(answer => {
console.log(answer) // 42
})
})
})
Made with ❤️ by radzom and all these wonderful contributors (emoji key):
Francis Pouatcha 🤔 |
Jan-Otto Kröpke 🚧 🚇 🐛 |
This project follows the all-contributors specification. Contributions of any kind are welcome!