How to use the tweetnacl.secretbox.keyLength function in tweetnacl

To help you get started, we’ve selected a few tweetnacl 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 liamgriffiths / tmpnote / src / lib / crypto.js View on Github external
// @flow

import { randomBytes, secretbox } from 'tweetnacl'
import { encodeUTF8, decodeUTF8, encodeBase64, decodeBase64 } from 'tweetnacl-util'

const NONCE_LEN = secretbox.nonceLength
const KEY_LEN = secretbox.keyLength

type Utf8 = string
type Base64 = string

const generateCredentials: () => { nonce: Uint8Array, key: Uint8Array }
= () => ({
  nonce: randomBytes(NONCE_LEN),
  key: randomBytes(KEY_LEN),
})

const join: (Uint8Array, Uint8Array) => Uint8Array
= (a, b) => {
  const c = new Uint8Array(a.length + b.length)
  c.set(a)
  c.set(b, a.length)
  return c
github olymp / olymp / external / crypt / tweetnacl-v1.es6 View on Github external
export const generateRandomKey = () =>
  encodeBase64(randomBytes(secretbox.keyLength));
export const generatePasswordShaKey = (
github fidm / quic / src / internal / crypto.ts View on Github external
constructor () {
    this.key = randomBytes(secretbox.keyLength)
  }