How to use the libp2p-crypto.aes 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 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
              }
            })
          } else {
            cipher.encrypt(Buffer.from(message.value), async (err, encrypted) =&gt; {
              if (!err) {
                const hashed = (await ipfs.files.add(encrypted))[0]
github peer-base / peer-base / test / collaboration-protocol.spec.js View on Github external
return new Promise((resolve, reject) => {
          crypto.aes.create(Buffer.from(key), Buffer.from(iv), (err, key) => {
            if (err) {
              return reject(err)
            }
            resolve(key)
          })
        })
      }
github peer-base / peer-base / test / shared.spec.js View on Github external
return new Promise((resolve, reject) => {
      crypto.aes.create(Buffer.from(key), Buffer.from(iv), (err, key) => {
        if (err) {
          return reject(err)
        }
        resolve(key)
      })
    })
  }
github peer-base / peer-pad / src / keys / parse.js View on Github external
  return (callback) => crypto.aes.create(keyBytes, iv, callback)
}
github ipfs-shipyard / peer-pad-core / src / backend / keys / parse-symm-key.js View on Github external
'use strict'

const b58Decode = require('bs58').decode
const crypto = require('libp2p-crypto')
const pify = require('pify')

const createKey = pify(crypto.aes.create.bind(crypto.aes))

const defaultOptions = {
  keyLength: 32,
  ivLength: 16
}

function parseSymmetricalKey (string, _options) {
  const options = Object.assign({}, defaultOptions, _options)
  const rawKey = b58Decode(string)

  return createKey(
    rawKey.slice(0, options.keyLength),
    rawKey.slice(options.keyLength, options.keyLength + options.ivLength))
}

module.exports = parseSymmetricalKey
github ipfs-shipyard / peer-pad-core / src / backend / keys / generate-symm-key.js View on Github external
return new Promise((resolve, reject) => {
    crypto.aes.create(rawKey.slice(0, options.keyLength), rawKey.slice(options.keyLength), (err, key) => {
      if (err) {
        return reject(err)
      }
      resolve({
        raw: rawKey,
        key: key
      })
    })
  })
}
github peer-base / peer-base / src / keys / derive-cipher-from-keys.js View on Github external
return new Promise((resolve, reject) => {
      crypto.aes.create(Buffer.from(key).slice(0, 32), Buffer.from(iv).slice(0, 16), (err, key) => {
        if (err) {
          return reject(err)
        }
        resolve(key)
      })
    })
  }