How to use the libsodium-wrappers.crypto_aead_xchacha20poly1305_ietf_decrypt function in libsodium-wrappers

To help you get started, we’ve selected a few libsodium-wrappers 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 sjudson / paseto.js / lib / protocol / V2.js View on Github external
const nlen  = sodium.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES;
  const nonce = Buffer.from(payload).slice(0, nlen);

  // decrypt and verify

  let ad;
  try {
    ad = utils.pae(header, nonce, footer);
  } catch (ex) {
    return done(ex);
  }

  const ciphertext = Buffer.from(payload).slice(nlen, plen);

  const _plaintext = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(null, ciphertext, ad, nonce, key.raw());
  const plaintext  = Buffer.from(_plaintext);

  // format

  return plaintext.toString('utf-8');
}
github TankerHQ / sdk-js / packages / crypto / src / aead.js View on Github external
export function decryptAEAD(key: Uint8Array, iv: Uint8Array, ciphertext: Uint8Array, associatedData?: Uint8Array): Uint8Array {
  return sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(null, ciphertext, associatedData, iv, key);
}
github panva / paseto / lib / help / crypto_worker.js View on Github external
'xchacha20-poly1305-decrypt' (ciphertext, nonce, key, preAuth) {
      try {
        return sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(undefined, ciphertext, preAuth, nonce, key)
      } catch (err) {
        return false
      }
    }
  }