How to use the crypto-browserify.createCipheriv function in crypto-browserify

To help you get started, we’ve selected a few crypto-browserify 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 transcend-io / penumbra / src / encrypt.ts View on Github external
key: Buffer.from(
        crypto.getRandomValues(new Uint8Array(GENERATED_KEY_RANDOMNESS / 8)),
      ),
    };
  }

  const { id } = file;
  // eslint-disable-next-line no-param-reassign
  size = file.size || size;

  // Convert to Buffers
  const key = toBuff(options.key);
  const iv = Buffer.from(crypto.getRandomValues(new Uint8Array(IV_RANDOMNESS)));

  // Construct the decipher
  const cipher = createCipheriv('aes-256-gcm', key, iv);
  // Encrypt the stream
  return {
    ...file,
    // stream:
    //   file.stream instanceof ReadableStream
    //     ? encryptStream(file.stream, cipher, size)
    //     : encryptBuffer(file.stream, cipher),
    stream: encryptStream(
      id,
      file.stream instanceof ReadableStream
        ? file.stream
        : intoStream(file.stream),
      cipher,
      size,
      key,
      iv,
github irisnet / irisnet-crypto / src / chains / iris / crypto.js View on Github external
throw new Error("private key must be not empty")
        }
        const salt = Cryp.randomBytes(32);
        const iv = Cryp.randomBytes(16);
        const cipherAlg = Config.iris.keystore.cipherAlg;
        const kdf = Config.iris.keystore.kdf;
        const address = this.import(privateKeyHex).address;

        const kdfparams = {
            dklen: 32,
            salt: salt.toString("hex"),
            c: Config.iris.keystore.c,
            prf: "hmac-sha256"
        };
        const derivedKey = Cryp.pbkdf2Sync(Buffer.from(password), salt, kdfparams.c, kdfparams.dklen, "sha256");
        const cipher = Cryp.createCipheriv(cipherAlg, derivedKey.slice(0, 16), iv);
        if (!cipher) {
            throw new Error("Unsupported cipher")
        }

        const cipherBuffer = Buffer.concat([cipher.update(Buffer.from(privateKeyHex, "hex")), cipher.final()]);
        const bufferValue = Buffer.concat([derivedKey.slice(16, 32), cipherBuffer]);
        let hashCiper = Cryp.createHash("sha256");
        hashCiper.update(bufferValue);
        const mac = hashCiper.digest().toString("hex");
        return {
            version: "1",
            id: UUID.v4({
                random: Cryp.randomBytes(16)
            }),
            address: address,
            crypto: {