项目作者: davesag

项目描述 :
Jose-Simple allows the encryption and decryption of data using the JOSE (JSON Object Signing and Encryption) standard.
高级语言: JavaScript
项目地址: git://github.com/davesag/jose-simple.git
创建时间: 2017-08-10T06:31:26Z
项目社区:https://github.com/davesag/jose-simple

开源协议:

下载


jose-simple

Proper encryption ought to be simple, and widespread.

Jose-Simple simplifies the encryption and decryption of data using the JOSE (JSON Object Signing and Encryption) standard.

NPM

Caveats

Installation

  1. npm install jose-simple

Usage

  1. const jose = require('jose-simple')
  2. // You need a private / public JWE key pair.
  3. // Either load them from `.pem` files, create them, or somehow acquire them.
  4. // The private key must not have a passphrase or cypher!
  5. // see https://github.com/cisco/node-jose/issues/69#issuecomment-236133179
  6. // see also https://github.com/cisco/node-jose/issues/234#issuecomment-457615794
  7. // see unit tests for a simple example.
  8. const { encrypt, decrypt } = jose(privateKey, publicKey)
  9. const someData = {
  10. some: 'amazing data',
  11. you: 'want to keep hidden',
  12. from: 'prying eyes'
  13. }
  14. encrypt(someData).then(encrypted => {
  15. console.log('encrypted', encrypted)
  16. decrypt(encrypted).then(decrypted => {
  17. console.log('decrypted', decrypted)
  18. // decrypted will be the same as someData
  19. })
  20. })

Options

See encrypt.js#L660-L668

You can add encrypt options as follows:

  1. const { encrypt, decrypt } = jose(privateKey, publicKey, {
  2. format: 'compact'
  3. protect: true,
  4. // or any of the encrypt options than can be passed to JWE.createEncrypt.
  5. // https://github.com/cisco/node-jose/blob/master/lib/jwe/encrypt.js#L660-L668
  6. })

Development

Branch Status Coverage Audit Comment
develop CircleCI codecov Vulnerabilities Work in progress
main CircleCI codecov Vulnerabilities Latest release

Prerequisites

  • NodeJS, I use nvm to manage Node versions — brew install nvm.

Test it

  • npm test — runs the unit tests. The tests give an example of how to create key pairs too. (Leverages the crypto.generateKeyPair libraries introduced in Node 10.12.0.)
  • npm run test:unit:cov — runs the unit tests with code coverage

Lint it

  1. npm run lint

Contributing

Contributions are welcome. Please see CONTRIBUTING for more details.