How to use the libp2p-crypto.pbkdf2 function in libp2p-crypto

To help you get started, we’ve selected a few libp2p-crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libp2p / js-libp2p-keychain / src / keychain.js View on Github external
// Enforce NIST SP 800-132
    if (!opts.passPhrase || opts.passPhrase.length < 20) {
      throw new Error('passPhrase must be least 20 characters')
    }
    if (opts.dek.keyLength < NIST.minKeyLength) {
      throw new Error(`dek.keyLength must be least ${NIST.minKeyLength} bytes`)
    }
    if (opts.dek.salt.length < NIST.minSaltLength) {
      throw new Error(`dek.saltLength must be least ${NIST.minSaltLength} bytes`)
    }
    if (opts.dek.iterationCount < NIST.minIterationCount) {
      throw new Error(`dek.iterationCount must be least ${NIST.minIterationCount}`)
    }

    // Create the derived encrypting key
    const dek = crypto.pbkdf2(
      opts.passPhrase,
      opts.dek.salt,
      opts.dek.iterationCount,
      opts.dek.keyLength,
      opts.dek.hash)
    Object.defineProperty(this, '_', { value: () => dek })
  }
github textileio / encryptoid / src / main.js View on Github external
button.addEventListener('click', (e) => {
      output.innerHTML = ''
      if (!password.validity.valid) {
        return
      }
      e.preventDefault()
      // Compute a derived key to use in AES encryption algorithm
      // We aren't ever storing passwords, so no need to worry about salt
      const key = crypto.pbkdf2(password.value, 'encryptoid', 5000, 24, 'sha2-256')
      // We're only using the key once, so a fixed IV should be ok
      const iv = Buffer.from([...Array(16).keys()])
      // Create AES encryption object
      crypto.aes.create(Buffer.from(key), iv, (err, cipher) => {
        if (!err) {
          if (isDecrypting) {
            cipher.decrypt(Buffer.from(message.value, 'base64'), async (err, plaintext) => {
              if (!err) {
                const info = `Your super secret message is:
                `
                const msg = `${plaintext.toString('utf-8')}`
                const create = `<br><a href="${base}">create your own...</a>`
                output.innerText = info + '"' + msg + '"'
                output.innerHTML = output.innerHTML + create
              }
            })