How to use randombytes - 10 common examples

To help you get started, we’ve selected a few randombytes 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 ethereum / web3.js / packages / web3-eth-accounts / src / models / Account.js View on Github external
toV3Keystore(password, options) {
        options = options || {};
        const salt = options.salt || randomBytes(32);
        const iv = options.iv || randomBytes(16);

        let derivedKey;
        const kdf = options.kdf || 'scrypt';
        const kdfparams = {
            dklen: options.dklen || 32,
            salt: salt.toString('hex')
        };

        if (kdf === 'pbkdf2') {
            kdfparams.c = options.c || 262144;
            kdfparams.prf = 'hmac-sha256';
            derivedKey = pbkdf2Sync(
                Buffer.from(password),
                Buffer.from(kdfparams.salt, 'hex'),
                kdfparams.c,
github ethereum / web3.js / packages / web3-eth-accounts / src / models / Account.js View on Github external
throw new Error('Unsupported cipher');
        }

        const ciphertext = Buffer.concat([
            cipher.update(Buffer.from(this.privateKey.replace('0x', ''), 'hex')),
            cipher.final()
        ]);

        const mac = keccak256(Buffer.concat([derivedKey.slice(16, 32), Buffer.from(ciphertext, 'hex')])).replace(
            '0x',
            ''
        );

        return {
            version: 3,
            id: uuid.v4({random: options.uuid || randomBytes(16)}),
            address: this.address.toLowerCase().replace('0x', ''),
            crypto: {
                ciphertext: ciphertext.toString('hex'),
                cipherparams: {
                    iv: iv.toString('hex')
                },
                cipher: options.cipher || 'aes-128-ctr',
                kdf,
                kdfparams,
                mac: mac.toString('hex')
            }
        };
    }
github digidem / react-mapfilter / src / selectors / filterable_features.js View on Github external
function uniqueId (f) {
  return randomBytes(8).toString('hex')
}
github iotexproject / iotex-antenna / src / account / wallet.ts View on Github external
export function encrypt(
  privateKey: string,
  password: string,
  opts: EncryptOptions = {}
): PrivateKey {
  const account = privateKeyToAccount(privateKey);

  const salt = opts.salt || randomBytes(32);
  const iv = opts.iv || randomBytes(16);

  let derivedKey;
  const kdf = opts.kdf || "scrypt";
  const kdfparams: Kdfparams = {
    dklen: opts.dklen || 32,
    salt: salt.toString("hex")
  };

  if (kdf === "pbkdf2") {
    kdfparams.c = opts.c || 262144;
    kdfparams.prf = "hmac-sha256";
    derivedKey = crypto.pbkdf2Sync(
      Buffer.from(password),
      salt,
      kdfparams.c,
github Automattic / simplenote-electron / lib / utils / crypto-random-string.js View on Github external
const cryptoRandomString = len => {
  if (!Number.isFinite(len)) {
    throw new TypeError('Expected a finite number');
  }

  return randomBytes(Math.ceil(len / 2))
    .toString('hex')
    .slice(0, len);
};
github ethereum / web3.js / packages / web3-eth-accounts / src / models / Account.js View on Github external
toV3Keystore(password, options) {
        options = options || {};
        const salt = options.salt || randomBytes(32);
        const iv = options.iv || randomBytes(16);

        let derivedKey;
        const kdf = options.kdf || 'scrypt';
        const kdfparams = {
            dklen: options.dklen || 32,
            salt: salt.toString('hex')
        };

        if (kdf === 'pbkdf2') {
            kdfparams.c = options.c || 262144;
            kdfparams.prf = 'hmac-sha256';
            derivedKey = pbkdf2Sync(
                Buffer.from(password),
                Buffer.from(kdfparams.salt, 'hex'),
                kdfparams.c,
                kdfparams.dklen,
github swagger-api / swagger-ui / src / core / utils.js View on Github external
export function generateCodeVerifier() {
  return b64toB64UrlEncoded(
    randomBytes(32).toString("base64")
  )
}
github aws-amplify / amplify-js / packages / amazon-cognito-identity-js / src / AuthenticationHelper.js View on Github external
generateRandomSmallA() {
    const hexRandom = randomBytes(128).toString('hex');

    const randomBigInt = new BigInteger(hexRandom, 16);
    const smallABigInt = randomBigInt.mod(this.N);

    return smallABigInt;
  }
github bigearth / bitbox-cli / src / Crypto.js View on Github external
static randomBytes(size = 16) {
    return randomBytes(size);
  }
}

randombytes

random bytes from browserify stand alone

MIT
Latest version published 6 years ago

Package Health Score

71 / 100
Full package analysis

Popular randombytes functions