How to use the node-forge.util function in node-forge

To help you get started, we’ve selected a few node-forge 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 developmentseed / observe / app / actions / map.js View on Github external
const fn = async (dispatch, getState) => {
    const offlineResources = getOfflineResources(getState())

    // generate a random ID to identify this resource
    const id = forge.util.bytesToHex(forge.random.getBytes(4))

    if (offlineResources[id] != null) {
      return dispatch({
        type: types.OFFLINE_RESOURCE_ALREADY_EXISTS,
        id,
        name
      })
    }

    // MapboxGL expects these as [[maxX, maxY], [minX, minY]]
    const bounds = [[aoi[2], aoi[3]], [aoi[0], aoi[1]]]

    dispatch({
      type: types.FETCHING_OFFLINE_RESOURCES,
      id,
      name,
github enigmampc / secret-contracts / enigma-lib / enigma-utils.js View on Github external
function decryptMessage (key_hex, msg) {
    let key = forge.util.hexToBytes (key_hex);
    let msg_buf = Buffer.from (msg, 'hex');
    let iv = forge.util.createBuffer (msg_buf.slice (-12).toString ('binary'));
    let tag = forge.util.createBuffer (msg_buf.slice (-28, -12).toString ('binary'));
    const decipher = forge.cipher.createDecipher ('AES-GCM', key);

    decipher.start ({ iv: iv, tag: tag });
    decipher.update (forge.util.createBuffer (msg_buf.slice (0, -28).toString ('binary')));
    if (decipher.finish ()) {
        return decipher.output.getBytes ();
    }
}
github bitwarden / browser / src / services / crypto.service.ts View on Github external
async decrypt(cipherString: CipherString, key?: SymmetricCryptoKey,
        outputEncoding: string = 'utf8'): Promise {
        const ivBytes: string = forge.util.decode64(cipherString.initializationVector);
        const ctBytes: string = forge.util.decode64(cipherString.cipherText);
        const macBytes: string = cipherString.mac ? forge.util.decode64(cipherString.mac) : null;
        const decipher = await this.aesDecrypt(cipherString.encryptionType, ctBytes, ivBytes, macBytes, key);
        if (!decipher) {
            return null;
        }

        if (outputEncoding === 'utf8') {
            return decipher.output.toString('utf8');
        } else {
            return decipher.output.getBytes();
        }
    }
github kobotoolbox / enketo-express / public / js / src / module / encryptor.js View on Github external
function _rsaEncrypt( byteString, publicKey ) {
    const encrypted = publicKey.encrypt( byteString, ASYMMETRIC_ALGORITHM, ASYMMETRIC_OPTIONS );
    return forge.util.encode64( encrypted );
}
github Levino / mock-jwks / tools.ts View on Github external
publicKey,
  jwksOrigin,
}: {
  privateKey: forge.pki.PrivateKey
  publicKey: forge.pki.PublicKey
  jwksOrigin?: string
}): JWKS => {
  const helperKey = new NodeRSA()
  helperKey.importKey(forge.pki.privateKeyToPem(privateKey))
  const { n: modulus, e: exponent } = helperKey.exportKey('components')
  const certPem = createCertificate({
    jwksOrigin,
    privateKey,
    publicKey,
  })
  const certDer = forge.util.encode64(
    forge.asn1
      .toDer(forge.pki.certificateToAsn1(forge.pki.certificateFromPem(certPem)))
      .getBytes()
  )
  const thumbprint = base64url.encode(getCertThumbprint(certDer))
  return {
    keys: [
      {
        alg: 'RSA256',
        e: String(exponent),
        kid: thumbprint,
        kty: 'RSA',
        n: modulus.toString('base64'),
        use: 'sig',
        x5c: [certDer],
        x5t: thumbprint,
github over140 / mixwallet / web / src / api / mixin.js View on Github external
label: sessionId
    });
    let time = new Uint64LE(moment.utc().unix());
    time = [...time.toBuffer()].reverse();
    iterator = new Uint64LE(iterator);
    iterator = [...iterator.toBuffer()].reverse();
    pin = Buffer.from(pin, 'utf8');
    let buf = Buffer.concat([pin, Buffer.from(time), Buffer.from(iterator)]);
    let padding = blockSize - buf.length % blockSize;
    let paddingArray = [];
    for (let i=0; i
github UCSD / campus-mobile / app / util / auth.js View on Github external
encryptStringWithBase64(string) {
		return forge.util.encode64(string)
	},