Socket
Book a DemoInstallSign in
Socket

masq-crypto

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

masq-crypto

Crypto wrapper for Masq

0.0.1
latest
Source
npmnpm
Version published
Weekly downloads
9
800%
Maintainers
1
Weekly downloads
 
Created
Source

Masq Crypto Library

Promise-based crypto library used by Qwant Masq. It allows applications to encrypt and decrypt JSON data. The cipher used is AES GCM which provides integrity and confidentiality.

The library includes a passphrase generator and key derivation using the PBKDF2 algorithm.

Install

Developer

git clone https://github.com/QwantResearch/masq-crypto.git
cd masq-crypto
npm install

Example usage

Add the client JS reference in your page:

<script type="text/javascript" src="src/index.js"></script>

Using the crypto library in your app:

// EXAMPLE
const apiData = { POI_1: 'Tour eiffel', POI_2: 'Cafeteria'}

// If no passphrase is given, it will be generated.
deriveKey('').then(function (derivedKey) {
  // encryption
  encrypt(derivedKey, JSON.stringify(apiData), '1.0.0').then(function (encryptedJson) {
    console.log(encryptedJson)
    // Object { ciphertext: "cb9a804…", iv: "145a65b6535d00b5a3cce475", version: "1.0.0" }

    // decryption
    decrypt(derivedKey, encryptedJson).then(function (decryptedJson) {
      console.log(decryptedJson) // { POI_1: "Tour eiffel", POI_2: "Cafeteria"}
    })
  })
})

Utils functions

Useful functions to convert between ArrayBuffer - String and hexString, examples:

let testRes = ''
if (toString(toArray('bonjour')) !== 'bonjour') { testRes = 'Fail' } else { testRes = 'Success' }
console.log('array <-> ascii conversion :' + testRes)
if (bufferToHexString(hexStringToBuffer('11a1b2')) !== '11a1b2') { testRes = 'Fail' } else { testRes = 'Success' }
console.log('array <-> hexString conversion : ' + testRes)

License

Apache-2.0

FAQs

Package last updated on 01 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.