首页 > 解决方案 > CryptoJS 的 crypto.createCipheriv 等价物是什么?

问题描述

我想为 Redsys 制作一个签名令牌,但我发现的所有加密方法都在 javascript native、java 或 php 中。

我为 NodeJs 找到了这个Redsys Api,但加密不兼容。所以我尝试切换到 CryptoJS,但该createCipheriv功能不适用于 CryptoJs。

我想做的事...

  signature( key ){
    var thisObj = this;

    function getOrderId(){
        var ret;

        thisObj.params.forEach(function(item, key){
            if (key.toUpperCase() === 'DS_MERCHANT_ORDER'){
                ret = item;
          return -1; }
        })
        return ret;
    }

    var iv = Buffer.alloc( 8, 0, 'utf8' );
    var cipher = CryptoJS.createCipheriv('des-ede3-cbc', Buffer.from( key , 'base64'), iv);
    cipher.setAutoPadding(false);

    var orderId = Buffer.from(getOrderId());
    var pad = Buffer.alloc((Math.ceil(orderId.length / 8) * 8) - orderId.length, 0);

    key = Buffer.concat([cipher.update(orderId), cipher.update(pad), cipher.final()]);

    var hash = CryptoJS.createHmac( 'sha256', key );
    hash.update(Buffer.from(this.createMerchantParameters()));
    return hash.digest('base64');
  }

/// ERROR Error: Uncaught (in promise): TypeError: crypto_js__WEBPACK_IMPORTED_MODULE_3__.createCipheriv is not a function

CryptoJS 的 crypto.createCipheriv 等价物是什么?

标签: javascriptionic4cryptojs

解决方案


推荐阅读