How to use the webcrypto-core.BufferSourceConverter.toUint8Array function in webcrypto-core

To help you get started, we’ve selected a few webcrypto-core 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 PeculiarVentures / webcrypto / src / mechs / hkdf / hkdf.ts View on Github external
public async onDeriveBits(params: HkdfParams, baseKey: HkdfCryptoKey, length: number): Promise {
    const hash = (params.hash as Algorithm).name.replace("-", "");
    const hashLength = crypto.createHash(hash).digest().length;

    const byteLength = length / 8;
    const info = BufferSourceConverter.toUint8Array(params.info);

    const PRK = crypto.createHmac(hash, BufferSourceConverter.toUint8Array(params.salt))
        .update(BufferSourceConverter.toUint8Array(baseKey.data))
        .digest();

    const blocks = [Buffer.alloc(0)];
    const blockCount = Math.ceil(byteLength / hashLength) + 1; // Includes empty buffer
    for (let i = 1; i < blockCount; ++i) {
      blocks.push(
          crypto.createHmac(hash, PRK)
            .update(Buffer.concat([blocks[i - 1], info, Buffer.from([i])]))
            .digest(),
      );
    }

    return Buffer.concat(blocks).slice(0, byteLength);
github PeculiarVentures / webcrypto / src / mechs / hkdf / hkdf.ts View on Github external
public async onDeriveBits(params: HkdfParams, baseKey: HkdfCryptoKey, length: number): Promise {
    const hash = (params.hash as Algorithm).name.replace("-", "");
    const hashLength = crypto.createHash(hash).digest().length;

    const byteLength = length / 8;
    const info = BufferSourceConverter.toUint8Array(params.info);

    const PRK = crypto.createHmac(hash, BufferSourceConverter.toUint8Array(params.salt))
        .update(BufferSourceConverter.toUint8Array(baseKey.data))
        .digest();

    const blocks = [Buffer.alloc(0)];
    const blockCount = Math.ceil(byteLength / hashLength) + 1; // Includes empty buffer
    for (let i = 1; i < blockCount; ++i) {
      blocks.push(
          crypto.createHmac(hash, PRK)
            .update(Buffer.concat([blocks[i - 1], info, Buffer.from([i])]))
            .digest(),
      );
    }

    return Buffer.concat(blocks).slice(0, byteLength);
  }
github PeculiarVentures / webcrypto / src / mechs / hkdf / hkdf.ts View on Github external
public async onDeriveBits(params: HkdfParams, baseKey: HkdfCryptoKey, length: number): Promise {
    const hash = (params.hash as Algorithm).name.replace("-", "");
    const hashLength = crypto.createHash(hash).digest().length;

    const byteLength = length / 8;
    const info = BufferSourceConverter.toUint8Array(params.info);

    const PRK = crypto.createHmac(hash, BufferSourceConverter.toUint8Array(params.salt))
        .update(BufferSourceConverter.toUint8Array(baseKey.data))
        .digest();

    const blocks = [Buffer.alloc(0)];
    const blockCount = Math.ceil(byteLength / hashLength) + 1; // Includes empty buffer
    for (let i = 1; i < blockCount; ++i) {
      blocks.push(
          crypto.createHmac(hash, PRK)
            .update(Buffer.concat([blocks[i - 1], info, Buffer.from([i])]))
            .digest(),
      );
    }

    return Buffer.concat(blocks).slice(0, byteLength);
  }