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


TypeScript crypto.createCipheriv函数代码示例

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


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

示例1: encryptWithIV

function encryptWithIV(text: string, iv: Buffer, opts: Options): string {
  setupKeys(opts);

  const cipher = createCipheriv(
    opts.encryptionAlgorithm as string,
    opts.encryptionKey,
    iv
  );

  const plaintext = Buffer.from(text, 'utf8');
  const ciphertextStart = forceBuffer(cipher.update(plaintext));
  zeroBuffer(plaintext);

  const ciphertextEnd = forceBuffer(cipher.final());
  const ciphertext = Buffer.concat([ciphertextStart, ciphertextEnd]);
  zeroBuffer(ciphertextStart);
  zeroBuffer(ciphertextEnd);

  const mac = computeHmac(iv, ciphertext, opts);

  const result = [
    B.encode(iv),
    B.encode(ciphertext),
    B.encode(mac),
  ].join('.');

  zeroBuffer(iv);
  zeroBuffer(ciphertext);
  zeroBuffer(mac);

  return result;
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:32,代码来源:encrypt.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: encryptPrivateKey

export function encryptPrivateKey(privKey, pubKey, encryptionKey) {
  const key = encryptionKey;
  const doubleHash = Buffer.from(SHA256(SHA256(pubKey)), 'hex');
  const iv = doubleHash.slice(0, 16);
  const cipher = crypto.createCipheriv(algo, key, iv);
  const encData = cipher.update(privKey, 'utf8', 'hex') + cipher.final('hex');
  return encData;
}
开发者ID:bitjson,项目名称:bitcore,代码行数:8,代码来源:encryption.ts

示例4: encryptEncryptionKey

export function encryptEncryptionKey(encryptionKey, password) {
  const password_hash = Buffer.from(SHA512(password));
  const key = password_hash.slice(0, 32);
  const iv = password_hash.slice(32, 48);
  const cipher = crypto.createCipheriv(algo, key, iv);
  const encData =
    cipher.update(encryptionKey, 'hex', 'hex') + cipher.final('hex');
  return encData;
}
开发者ID:bitjson,项目名称:bitcore,代码行数:9,代码来源:encryption.ts

示例5:

export const encryptValue = (value: string): string => {
    const iv = IV_LENGTH ? crypto.randomBytes(IV_LENGTH) : null;
    const cipher = crypto.createCipheriv(ENCRYPTION_TYPE, Buffer.from(ENCRYPTION_KEY), iv);
    const encrypted = cipher.update(value);

    return [
        ENCRYPTION_TYPE,
        iv.toString('hex'),
        Buffer.concat([encrypted, cipher.final()]).toString('hex')
    ].join(':');
};
开发者ID:benjambles,项目名称:my-own-world,代码行数:11,代码来源:encrpytion.ts

示例6: encrypt

export function encrypt(mediaUrl: string, decryptKey: string, iv?: string) {
  const ivHex = iv ? Buffer.from(iv, 'hex') : randomBytes(IV_LENGTH)
  const encipher = createCipheriv(ALGORITHM, decryptKey, ivHex)

  const encrypted = Buffer.concat([
    ivHex,
    encipher.update(mediaUrl),
    encipher.final()
  ])

  return encrypted.toString('base64')
}
开发者ID:jsalonen,项目名称:yle-api,代码行数:12,代码来源:mediaurl.ts

示例7: pbkdf2

 return pbkdf2(password, salt, pbkdf2Iterations, pbkdf2KeyLen, pbkdf2Digest).then((key) => {
   const cipher = crypto.createCipheriv(cipherAlgorithm, key, iv);
   let value = cipher.update(JSON.stringify(json), 'utf8', 'base64');
   value += cipher.final('base64');
   let data: EncryptedJson<T> = {
     salt: salt.toString('base64'),
     iv: iv.toString('base64'),
     value: value
   };
   let tag = cipher.getAuthTag();
   if (tag) {
     data.tag = tag.toString('base64');
   }
   return data;
 });
开发者ID:relution-io,项目名称:relution-sdk,代码行数:15,代码来源:cipher.ts

示例8: encryptAES

export function encryptAES(params: any, config: IOPayConfig) {
  if (typeof params != "object")
    throw new Error(`Error encryptAES: params is invalid.`);
  let sec = ["HashKey", "HashIV"];
  sec.forEach(key => {
    delete params[key];
  });
  let encipher = crypto.createCipheriv(
    "aes-128-cbc",
    config.AIOHashKey,
    config.AIOHashIV
  );
  let text = params["PaymentToken"];
  let encrypted_base64 = Buffer.concat([
    encipher.update(text),
    encipher.final()
  ]).toString("base64");
  return urlEncodeDotNet(encrypted_base64);
}
开发者ID:EJayCheng,项目名称:oPay-ts,代码行数:19,代码来源:util.ts

示例9: encrypt

    /**
     * Encrypts the object by JSON serializing it and then calling AES.
     */
    public encrypt(data: string): string {

        Logger.log.debug("AesEncryptor.encrypt: start.");

        if (!this.passphrase) {
            throw new EncryptionError("Encryption passphrase not available.", "AES256");
        }

        let params: EncryptionParameters = this.createKeyAndIV();

        let cipher: Crypto.Cipher = Crypto.createCipheriv("aes256", params.key, params.iv);
        let encrypted: string = cipher.update(data, "utf8", "base64");
        encrypted += cipher.final("base64");

        params.data = Buffer.concat([new Buffer("Salted__", "utf8"), params.salt, new Buffer(encrypted, "base64")]);

        Logger.log.debug(`AesEncryptor.encrypt: encryption complete: '${encrypted}'.`);

        return params.data.toString("base64");
    }
开发者ID:cloudconfig,项目名称:cloco-node,代码行数:23,代码来源:aes-encryptor.ts

示例10: aes_encode

 static aes_encode(data: string): string {
    //使用的加密算法
    var algorithm ='AES-128-ECB';
    //使用的加密字符串
    var key = 'jydasai38hao1616';
    //输入的数据编码
    var inputEncoding = 'utf8';
    //初始化向量
    //输出数据编码
    var outputEncoding = 'base64';
    //创建加密器
    var cipher = crypto.createCipheriv(algorithm, key,"");
    cipher.setAutoPadding(true);
    //更新加密器:对数据进行加密
    var encodingStr = cipher.update(data,inputEncoding,outputEncoding);
    encodingStr += cipher.final(outputEncoding);
    //返回加密后字符串
    return encodingStr;
   
 }
开发者ID:stableShip,项目名称:EncryptTool,代码行数:20,代码来源:EncryptTool.ts


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