What is the crypto.createCipheriv equivalent for CryptoJS?

Viewed 191

I'm tring to make a signature token for Redsys, but the encription methods that i found where all in javascript native, java or php.

I found this Redsys Api for NodeJs but crypto was no compatible. So I tried to switch to CryptoJS but the createCipheriv fuction is not avaliable for CryptoJs.

What I'm tring to do...

  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

What is the crypto.createCipheriv equivalent for CryptoJS?

0 Answers
Related