当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript crypto.createHmac函数代码示例

本文整理汇总了TypeScript中crypto.createHmac函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createHmac函数的具体用法?TypeScript createHmac怎么用?TypeScript createHmac使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了createHmac函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: reject

            worker.request = new Promise<PhantomResult>((resolve, reject) => {
                const hmac = crypto.createHmac("sha256", worker.key)
                    .update([worker.counter, 'POST', '/', `localhost:${worker.port}`, 'application/json', payload].join('\n'))
                    .digest('hex');

                http.request({
                    port:    worker.port,
                    method:  'POST',
                    auth:    worker.counter + ':' + hmac,
                    headers: {
                        'Content-Type':   'application/json',
                        'Content-Length': payload.length,
                    },
                }, (response) => {
                    let result = '';

                    response.on('error', (error) => {
                        reject(error);
                    });

                    response.on('data', (data) => {
                        result += data;
                    });

                    response.on('end', () => {
                        resolve([response, result]);
                    });
                })
                .on('error', (error) => {
                    reject(error);
                })
                .end(payload);
            });
开发者ID:LeviticusMB,项目名称:ghostly,代码行数:33,代码来源:ghostly.ts

示例2: Error

  return Promise.resolve().then(() => {
    // must be bip39 mnemonic
    if (!bip39.validateMnemonic(phrase)) {
      throw new Error('Not a valid bip39 nmemonic')
    }

    // normalize plaintext to fixed length byte string
    const plaintextNormalized = Buffer.from(
      bip39.mnemonicToEntropy(phrase), 'hex'
    )

    // AES-128-CBC with SHA256 HMAC
    const salt = crypto.randomBytes(16)
    const keysAndIV = crypto.pbkdf2Sync(password, salt, 100000, 48, 'sha512')
    const encKey = keysAndIV.slice(0, 16)
    const macKey = keysAndIV.slice(16, 32)
    const iv = keysAndIV.slice(32, 48)

    const cipher = crypto.createCipheriv('aes-128-cbc', encKey, iv)
    let cipherText = cipher.update(plaintextNormalized).toString('hex')
    cipherText += cipher.final().toString('hex')

    const hmacPayload = Buffer.concat([salt, Buffer.from(cipherText, 'hex')])

    const hmac = crypto.createHmac('sha256', macKey)
    hmac.write(hmacPayload)
    const hmacDigest = hmac.digest()

    const payload = Buffer.concat([salt, hmacDigest, Buffer.from(cipherText, 'hex')])
    return payload
  })
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:31,代码来源:wallet.ts

示例3: function

 prototype.request = function(method, uriParts, opts, callback) {
     var self = this;
     opts = opts || {};
     method = method.toUpperCase();
     if (!callback && (opts instanceof Function)) {
         callback = opts;
         opts = {};
     }
     var relativeURI = self.makeRelativeURI(uriParts);
     _.assign(opts, {
         'method': method,
         'uri': self.makeAbsoluteURI(relativeURI),
     });
     if (opts.body && (typeof opts.body !== 'string')) {
         opts.body = JSON.stringify(opts.body);
     }
     opts.agent = keepaliveAgent;
     var timestamp = Date.now() / 1000;
     var what = timestamp + method + relativeURI + (opts.body || '');
     var key = new Buffer(self.b64secret, 'base64');
     var hmac = crypto.createHmac('sha256', key);
     var signature = hmac.update(what).digest('base64');
     self.addHeaders(opts, {
         'CB-ACCESS-KEY': self.key,
         'CB-ACCESS-SIGN': signature,
         'CB-ACCESS-TIMESTAMP': timestamp,
         'CB-ACCESS-PASSPHRASE': self.passphrase,
     });
     request(opts, self.makeRequestCallback(callback));
 };
开发者ID:Camille92,项目名称:tribeca,代码行数:30,代码来源:coinbase-api.ts

示例4: TypeError

export function unsignSync<T extends UnknownRecord>(
  signature: string,
  secret: string,
  options?: SignaturOptions
): T {
  const { separator = '.' } = options || {} as SignaturOptions;

  if ('string' !== typeof(signature) || !signature.length) {
    throw new TypeError(`Expected 'signature' to be defined, but received '${signature}'`);
  }

  if ('string' !== typeof(secret) || !secret.length) {
    throw new TypeError(`Expected 'secret' to be defined, but received '${secret}'`);
  }

  const [hash, enc] = signature.split(separator, 2);
  const decoded = Buffer.from(
    (hash + '==='.slice((hash.length + 3) % 4))
      .replace(/\-/gi, '+')
      .replace(/_/gi, '/'), 'base64')
    .toString('utf8');
  const signedDecoded = urlSafeBase64(
    createHmac('sha256', secret).update(decoded).digest('base64'));

  if (enc !== signedDecoded) {
    throw new SignaturError('invalid_signature', 'Signature not match');
  }

  return (JSON.parse(decoded) as DecodedData<T>).data;
}
开发者ID:motss,项目名称:signatur,代码行数:30,代码来源:index.ts

示例5: makeNewUser

	private makeNewUser(email: string, password: string) {
		const solt = crypto.randomBytes(16).toString('hex');
		const hashPassword = crypto
			.createHmac("sha256", solt)
			.update(password)
			.digest('hex');

		const newUser = {
			UTC: new Date(),
			email: email,
			solt: solt,
			password: hashPassword,
		};

		this.sendMailToNewUser(email);

		return new Promise((resolve) => {
			this.db.collection("users").insert(newUser, (err) => {
				if (err) {
					resolve(false);
					return;
				}

				resolve(true);
				return;
			});
		});

	}
开发者ID:spear4life,项目名称:Socotra,代码行数:29,代码来源:auth.mod.ts

示例6: computeHmac

function computeHmac(iv: Buffer, ciphertext: Buffer, opts: Options) {
  const hmac = createHmac(opts.signatureAlgorithm as string, opts.signatureKey as Buffer);
  hmac.update(iv);
  hmac.update(ciphertext);

  return forceBuffer(hmac.digest());
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:7,代码来源:encrypt.ts

示例7: checkPassword

  /**
   * @returns {bool}
   */
  checkPassword (password: string) {
    const hashed = crypto
        .createHmac('sha1', this.salt + config.app.secret)
        .update(password)
        .digest('hex');

    return hashed === this.password;
  }
开发者ID:euoia,项目名称:node-mud,代码行数:11,代码来源:player.ts

示例8: return

const signBlob = (exports.signBlob = (key: string, blob: string) => {
  return (
    "sha1=" +
    crypto
      .createHmac("sha1", key)
      .update(blob)
      .digest("hex")
  );
});
开发者ID:ft-interactive,项目名称:ft-ig-github-project-manager,代码行数:9,代码来源:e2e.spec.ts

示例9: function

userSchema.methods.hashPassword = function(password: string): string {
	if (!password) {
		return '';
	}
	if (!this.password_salt) {
		return '';
	}
	return createHmac('sha1', this.password_salt).update(password).digest('hex');
};
开发者ID:freezy,项目名称:node-vpdb,代码行数:9,代码来源:user.schema.ts

示例10: webhookAuth

export function webhookAuth(req, res, next) {
  const createdHmac = createHmac("SHA256", getEnv(SHOPIFY_SHARED_SECRET)).update(new Buffer(req.rawBody, 'utf8')).digest('base64');
  const hmacHeader = req.get('HTTP_X_SHOPIFY_HMAC_SHA256');

  if (createdHmac !== hmacHeader) {
    console.warn('HTTP_X_SHOPIFY_HMAC_SHA256 header does not match calculated HMAC');
    return res.sendStatus(401);
  }

  next()
}
开发者ID:chmurson,项目名称:shopify,代码行数:11,代码来源:webhookAuth.ts


注:本文中的crypto.createHmac函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。