• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

TypeScript crypto.createDecipheriv函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: eciesDecrypt

    eciesDecrypt(recipientPrivateKey, cipherText) {
        var self = this;
        // debug("recipientPrivateKey=%s", util.inspect(recipientPrivateKey));//XXX
        var level = recipientPrivateKey.ecparams.keylen;
        var curveName = recipientPrivateKey.curveName;
        // debug("=============> %d", level);
        if (this.securityLevel != level) {
            throw Error("Invalid key. It's security does not match the current security level " +  this.securityLevel + " " + level);
        }
        //cipherText = ephemeralPubKeyBytes + encryptedTokBytes + macBytes
        //ephemeralPubKeyBytes = first ((384+7)/8)*2 + 1 bytes = first 97 bytes
        //hmac is sha3_384 = 48 bytes or sha3_256 = 32 bytes
        var Rb_len = Math.floor((level + 7) / 8) * 2 + 1;
        var D_len = level >> 3;
        var ct_len = cipherText.length;

        if (ct_len <= Rb_len + D_len)
            throw new Error("Illegal cipherText length: " + ct_len + " must be > " + (Rb_len + D_len));

        var Rb = cipherText.slice(0, Rb_len);  // ephemeral public key bytes
        var EM = cipherText.slice(Rb_len, ct_len - D_len);  // encrypted content bytes
        var D = cipherText.slice(ct_len - D_len);

        // debug("Rb :\n", new Buffer(Rb).toString('hex'));
        // debug("EM :\n", new Buffer(EM).toString('hex'));
        // debug("D  :\n", new Buffer(D).toString('hex'));

        var EC = elliptic.ec;
        //var curve = elliptic.curves['p'+level];
        var ecdsa = new EC('p' + level);

        //convert bytes to usable key object
        var ephPubKey = ecdsa.keyFromPublic(new Buffer(Rb, 'hex'), 'hex');
        //var encPrivKey = ecdsa.keyFromPrivate(ecKeypair2.prvKeyObj.prvKeyHex, 'hex');
        var privKey = ecdsa.keyFromPrivate(recipientPrivateKey.prvKeyHex, 'hex');
        // debug('computing Z...', privKey, ephPubKey);

        var Z = privKey.derive(ephPubKey.pub);
        // debug('Z computed', Z);
        // debug('secret:  ', new Buffer(Z.toArray(), 'hex'));
        var kdfOutput = self.hkdf(Z.toArray(), ECIESKDFOutput, null, null);
        var aesKey = kdfOutput.slice(0, AESKeyLength);
        var hmacKey = kdfOutput.slice(AESKeyLength, AESKeyLength + HMACKeyLength);
        // debug('secret:  ', new Buffer(Z.toArray(), 'hex'));
        // debug('aesKey:  ', new Buffer(aesKey, 'hex'));
        // debug('hmacKey: ', new Buffer(hmacKey, 'hex'));

        var recoveredD = self.hmac(hmacKey, EM);
        debug('recoveredD:  ', new Buffer(recoveredD).toString('hex'));

        if (D.compare(new Buffer(recoveredD)) != 0) {
            // debug("D="+D.toString('hex')+" vs "+new Buffer(recoveredD).toString('hex'));
            throw new Error("HMAC verify failed");
        }
        var iv = EM.slice(0, IVLength);
        var cipher = crypto.createDecipheriv('aes-256-cfb', new Buffer(aesKey), iv);
        var decryptedBytes = cipher.update(EM.slice(IVLength));
        // debug("decryptedBytes: ",new Buffer(decryptedBytes).toString('hex'));
        return decryptedBytes;
    }
开发者ID:Druson,项目名称:fabric,代码行数:60,代码来源:crypto.ts


示例2: decrypt

    /**
     * Decrypts the object using AES256.
     */
    public decrypt(encrypted: string): string {

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

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

        try {
            Logger.log.debug(`AesEncryptor.decrypt: encrypted data: ${encrypted}`);

            let params: EncryptionParameters = this.deriveKeyAndIV(encrypted);

            let decipher: Crypto.Decipher = Crypto.createDecipheriv("aes256", params.key, params.iv);
            let decrypted: string = decipher.update(params.content, "base64", "utf8");
            decrypted += decipher.final("utf8");

            Logger.log.debug(`AesEncryptor.decrypt: data decrypted successfully.`);

            return decrypted;
        } catch (e) {
            Logger.log.error(`AesEncryptor.decrypt: Failed to decrypt: ${e}`);
            throw new EncryptionError(`Failed to decrypt: ${e}`, "AES256");
        }
    }
开发者ID:cloudconfig,项目名称:cloco-node,代码行数:28,代码来源:aes-encryptor.ts


示例3: decryptPrivateKey

function decryptPrivateKey(encPrivateKey, pubKey, encryptionKey) {
  const key = Buffer.from(encryptionKey, 'hex');
  const doubleHash = Buffer.from(SHA256(SHA256(pubKey)), 'hex');
  const iv = doubleHash.slice(0, 16);
  const decipher = crypto.createDecipheriv(algo, key, iv);
  const decrypted =
    decipher.update(encPrivateKey, 'hex', 'utf8') + decipher.final('utf8');
  return decrypted;
}
开发者ID:bitjson,项目名称:bitcore,代码行数:9,代码来源:encryption.ts


示例4: decryptEncryptionKey

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


示例5:

export const decryptValue = (value: string): string => {
    const [type, iv, ...data] = value.split(':');
    const ivBuffer = iv === 'null' ? null : Buffer.from(iv, 'hex');
    const encryptedText = Buffer.from(data.join(':'), 'hex');
    const decipher = crypto.createDecipheriv(type, Buffer.from(ENCRYPTION_KEY), ivBuffer);
    const decrypted = decipher.update(encryptedText);

    return Buffer.concat([decrypted, decipher.final()]).toString();
};
开发者ID:benjambles,项目名称:my-own-world,代码行数:9,代码来源:encrpytion.ts


示例6: aes256GCMDecrypt

 static aes256GCMDecrypt(key:Buffer, ct:Buffer) {
     let decipher = crypto.createDecipheriv('aes-256-gcm', key, ct.slice(0, GCMStandardNonceSize));
     decipher.setAuthTag(ct.slice(ct.length - GCMTagSize));
     let dec = decipher.update(
         ct.slice(GCMStandardNonceSize, ct.length - GCMTagSize).toString('hex'),
         'hex', 'hex'
     );
     dec += decipher.final('hex');
     return dec;
 }
开发者ID:Druson,项目名称:fabric,代码行数:10,代码来源:crypto.ts


示例7: decryptString

    decryptString(data: EncryptedData): string
    {
        const
            secret = this.privKey.computeSecret(pubKeyToBuffer(data.pubKey)),
            iv = Buffer.alloc(16, 0),
            cipher = createDecipheriv("aes-256-cbc", secret, iv);

        let decrypted = cipher.update(data.payload, "base64", "utf8");
        decrypted += cipher.final("utf8");
        return decrypted;
    }
开发者ID:tera-insights,项目名称:tiFormEncrypt,代码行数:11,代码来源:DecryptorNode.ts


示例8: pbkdf2

 return pbkdf2(password, salt, pbkdf2Iterations, pbkdf2KeyLen, pbkdf2Digest).then((key) => {
   const iv = new Buffer(data.iv, 'base64');
   const decipher = crypto.createDecipheriv(cipherAlgorithm, key, iv);
   let tag = data.tag;
   if (tag) {
     decipher.setAuthTag(new Buffer(tag, 'base64'));
   }
   let value = decipher.update(data.value, 'base64', 'utf8');
   value += decipher.final('utf8');
   return value;
 }).then(JSON.parse);
开发者ID:relution-io,项目名称:relution-sdk,代码行数:11,代码来源:cipher.ts


示例9: decrypt

export function decrypt(encryptedData: string, encryptKey: string) {
  const encryptedBuffer = Buffer.from(encryptedData, 'base64').toString('hex')
  const iv = Buffer.alloc(IV_LENGTH, encryptedBuffer.substr(0, IV_LENGTH * 2), 'hex')
  const payload = Buffer.from(encryptedBuffer.substr(IV_LENGTH * 2), 'hex')
  const decipher = createDecipheriv(ALGORITHM, encryptKey, iv)

  const decrypted = Buffer.concat([
    decipher.update(payload),
    decipher.final()
  ])

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


示例10: decryptScalar

export function decryptScalar(value: any, key: Buffer, aad: string, digest: crypto.Hash | null, unencrypted: boolean) {
  if (unencrypted || typeof value !== 'string') {
    if (digest) {
      digest.update(toBytes(value));
    }

    return value;
  }

  const valre = value.match(/^ENC\[AES256_GCM,data:(.+),iv:(.+),tag:(.+),type:(.+)\]/);
  if (!valre) {
    return value;
  }

  const encValue = Buffer.from(valre[1], 'base64');
  const iv = Buffer.from(valre[2], 'base64');
  const tag = Buffer.from(valre[3], 'base64');
  const valtype = valre[4];

  var decryptor = crypto.createDecipheriv('aes-256-gcm', key, iv);

  decryptor.setAuthTag(tag);
  decryptor.setAAD(Buffer.from(aad));

  const cleartext = decryptor.update(encValue, undefined, 'utf8') + decryptor.final('utf8');

  if (digest) {
    digest.update(cleartext);
  }

  switch (valtype) {
    case 'bytes':
      return cleartext;
    case 'str':
      return cleartext;
    case 'int':
      return parseInt(cleartext, 10);
    case 'float':
      return parseFloat(cleartext);
    case 'bool':
      return cleartext === 'true';
    default:
      throw new SopsError("Unknown type ${type}");
  }
}
开发者ID:koblas,项目名称:sops-decoder-node,代码行数:45,代码来源:decode.ts


示例11: PasswordError

  return Promise.resolve().then(() => {
    const salt = dataBuffer.slice(0, 16)
    const hmacSig = dataBuffer.slice(16, 48)   // 32 bytes
    const cipherText = dataBuffer.slice(48)
    const hmacPayload = Buffer.concat([salt, cipherText])

    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 decipher = crypto.createDecipheriv('aes-128-cbc', encKey, iv)
    let plaintext = decipher.update(cipherText).toString('hex')
    plaintext += decipher.final().toString('hex')

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

    // hash both hmacSig and hmacDigest so string comparison time
    // is uncorrelated to the ciphertext
    const hmacSigHash = crypto.createHash('sha256')
      .update(hmacSig)
      .digest()
      .toString('hex')

    const hmacDigestHash = crypto.createHash('sha256')
      .update(hmacDigest)
      .digest()
      .toString('hex')

    if (hmacSigHash !== hmacDigestHash) {
      // not authentic
      throw new PasswordError('Wrong password (HMAC mismatch)')
    }

    const mnemonic = bip39.entropyToMnemonic(plaintext)
    if (!bip39.validateMnemonic(mnemonic)) {
      throw new PasswordError('Wrong password (invalid plaintext)')
    }

    return mnemonic
  })
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:43,代码来源:wallet.ts


示例12: decrypt

export function decrypt(encrypted: string, opts: Options): Either<string, string> {
  const components = encrypted.split('.');
  if (components.length !== 3) return left('Invalid payload');

  setupKeys(opts);

  const iv: Buffer = B.toBuffer(components[0]);
  const ciphertext = B.toBuffer(components[1]);
  const hmac = B.toBuffer(components[2]);

  function cleanup() {
    if (iv) zeroBuffer(iv);

    if (ciphertext) zeroBuffer(ciphertext);

    if (hmac) zeroBuffer(hmac);

    if (expectedHmac) zeroBuffer(expectedHmac);
  }

  // make sure IV is right length
  if (iv.length !== 16) {
    cleanup();
    return left('invalid iv length');
  }

  const expectedHmac = computeHmac(iv, ciphertext, opts);
  if (!timingSafeEqual(hmac, expectedHmac)) {
    cleanup();
    return left('invalid signature');
  }

  const decipher = createDecipheriv(
    opts.encryptionAlgorithm as string,
    opts.encryptionKey,
    iv
  );
  let plaintext = decipher.update(ciphertext, 'binary', 'utf8');
  plaintext += decipher.final('utf8');

  cleanup();
  return right(plaintext);
}
开发者ID:syaiful6,项目名称:jonggrang,代码行数:43,代码来源:encrypt.ts


示例13: aes_decode

     static aes_decode(encodingStr: string): string {
        //使用的算法
        var algorithm = 'AES-128-ECB';
        //使用的密匙
        var key = 'jydasai38hao1616';
        //输出的格式
        var outputEncoding = 'utf8';
        //输入数据编码
        var inputEncoding = 'base64';
        //创建解密器
        var decipher = crypto.createDecipheriv(algorithm, key,"");
        decipher.setAutoPadding(true);

        //解密数据
        var data = decipher.update(encodingStr,inputEncoding,outputEncoding);
        data += decipher.final(outputEncoding);
        return data;
      

     } 
开发者ID:stableShip,项目名称:EncryptTool,代码行数:20,代码来源:EncryptTool.ts


示例14:

    const nonce = crypto.randomBytes(12);
    const aad = Buffer.from('0123456789', 'hex');

    const cipher = crypto.createCipheriv('aes-192-ccm', key, nonce, {
        authTagLength: 16
    });
    const plaintext = 'Hello world';
    cipher.setAAD(aad, {
        plaintextLength: Buffer.byteLength(plaintext)
    });
    const ciphertext = cipher.update(plaintext, 'utf8');
    cipher.final();
    const tag = cipher.getAuthTag();

    const decipher = crypto.createDecipheriv('aes-192-ccm', key, nonce, {
        authTagLength: 16
    });
    decipher.setAuthTag(tag);
    decipher.setAAD(aad, {
        plaintextLength: ciphertext.length
    });
    const receivedPlaintext: string = decipher.update(ciphertext, null, 'utf8');
    decipher.final();
}

{
    const key = 'keykeykeykeykeykeykeykey';
    const nonce = crypto.randomBytes(12);
    const aad = Buffer.from('0123456789', 'hex');

    const cipher = crypto.createCipheriv('aes-192-gcm', key, nonce);
开发者ID:SaschaNaz,项目名称:DefinitelyTyped,代码行数:31,代码来源:crypto.ts


示例15: createDeOrCipher

function createDeOrCipher(type: string, algorithm: string, password: string, iv?: Buffer): { cipher: crypto.Cipher | crypto.Decipher, iv: Buffer } {
  let cipherAlgorithm = algorithm.toLowerCase();
  let keyIv = SupportedCiphers[cipherAlgorithm];
  
  if (!keyIv) {
    cipherAlgorithm = 'aes-256-cfb';
    keyIv = SupportedCiphers[cipherAlgorithm];
  }
  
  let key = new Buffer(password);
  let keyLength = keyIv[0];
  
  if (key.length > keyLength) key = key.slice(0, keyLength);
  if (key.length < keyLength) key = new Buffer(password.repeat(keyLength / password.length + 1)).slice(0, keyLength);
  
  iv = iv || crypto.randomBytes(keyIv[1]);
  
  let cipher = type === 'cipher' ? crypto.createCipheriv(cipherAlgorithm, key, iv) : crypto.createDecipheriv(cipherAlgorithm, key, iv);
  
  return { cipher, iv };
}
开发者ID:52M,项目名称:LightSword,代码行数:21,代码来源:cipher.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript crypto.createHash函数代码示例发布时间:2022-05-24
下一篇:
TypeScript crypto.createDecipher函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap