RangeError: Invalid array length
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)
The same problem
The same problem
This error is triggered when you pass an object, rather than a string.
It's 2020 and I still get the same problem
Same problem here, even passing a simple string
Este error se activa cuando pasa un objeto, en lugar de una cadena.
it's true..
When the same thing happened to me I "stringify"
CryptoJS.AES.encrypt( JSON.stringify({
username: username,
text: text,
createdAt: new Date().getTime()
}), '123456').toString();
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();
exacto! mi problema fue por pasar un parametro de tipo numero. Primero tuve que pasarlo a string para encriptarlo.