Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Invalid array length #16

Open
sukeerthimogallapalli opened this issue Jan 30, 2019 · 10 comments
Open

RangeError: Invalid array length #16

sukeerthimogallapalli opened this issue Jan 30, 2019 · 10 comments

Comments

@sukeerthimogallapalli
Copy link

No description provided.

@sukeerthimogallapalli
Copy link
Author

sukeerthimogallapalli commented Jan 30, 2019

Hi

i am trying to decrypt private key but i am getting this error

/home/ahex/Desktop/tokenize.node/node_modules/crypto-js/core.js:272
words.length = Math.ceil(sigBytes / 4);
^

RangeError: Invalid array length
at WordArray.init.clamp (/home/ahex/Desktop/tokenize.node/node_modules/crypto-js/core.js:272:27)
at WordArray.init.concat (/home/ahex/Desktop/tokenize.node/node_modules/crypto-js/core.js:237:19)

My code :

var CryptoJS = require('crypto-js')
var cryptoSecret = '*************************'
var SenderPrivateKey = new bitcore.PrivateKey('testnet');
console.log(SenderPrivateKey)
//<PrivateKey: 8c6251ff3ee21e54bc15485c2ea8f7491501a7a684ecc08dfd95a993f048e06e, network: //testnet>

var a = CryptoJS.AES.encrypt(SenderPrivateKey, cryptoSecret)

@sukeerthimogallapalli sukeerthimogallapalli changed the title /home/ahex/Desktop/tokenize.node/node_modules/crypto-js/core.js:272 words.length = Math.ceil(sigBytes / 4); ^ RangeError: Invalid array length at WordArray.init.clamp (/home/ahex/Desktop/tokenize.node/node_modules/crypto-js/core.js:272:27) at WordArray.init.concat (/home/ahex/Desktop/tokenize.node/node_modules/crypto-js/core.js:237:19) RangeError: Invalid array length Jan 30, 2019
@dmytro-kupriianov
Copy link

The same problem

1 similar comment
@Synat
Copy link

Synat commented May 5, 2020

The same problem

@michaelpeterlee
Copy link

michaelpeterlee commented May 11, 2020

This error is triggered when you pass an object, rather than a string.

@gocreating
Copy link

It's 2020 and I still get the same problem

@JuanxCursed
Copy link

Same problem here, even passing a simple string

@yquintana
Copy link

Este error se activa cuando pasa un objeto, en lugar de una cadena.

it's true..

@nezihsunman
Copy link

When the same thing happened to me I "stringify"

CryptoJS.AES.encrypt( JSON.stringify({
    username: username,
    text: text,
    createdAt: new Date().getTime()
  }), '123456').toString();

@midhun1993
Copy link

For me this issue occurred due to the type number.

So I did like this:

function transformToSafePayload(payload) {
  if (typeof payload == 'object') {
    return JSON.stringify(payload);
  }
  if (typeof payload != 'string') {
    return payload.toString();
  }
  return payload;
}


CryptoJS.AES.encrypt(transformToSafePayload({
    username: username,
    text: text,
    createdAt: new Date().getTime()
  }), '123456').toString();

@mcaceresDev
Copy link

exacto! mi problema fue por pasar un parametro de tipo numero. Primero tuve que pasarlo a string para encriptarlo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants