So entschlüsseln Sie Cookies mit nodejs

Ich versuche, @ zu machrun this

function hex2a(hex) {
    var str = '';
    for (var i = 0; i < hex.length; i += 2)
        str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
    return str;
}

//Raw cookie
var cookie = "B417B464CA63FE780584563D2DA4709B03F6195189044C26A29770F3203881DD90B1428139088D945CF6807CA408F201DABBADD59CE1D740F853A894692273F1CA83EC3F26493744E3D25D720374E03393F71E21BE2D96B6110CB7AC12E44447FFBD810D3D57FBACA8DF5249EB503C3DFD255692409F084650EFED205388DD8C08BF7B941E1AC1B3B70B9A8E09118D756BEAFF25834E72357FD40E80E76458091224FAE8";

//decryptionKey from issuers <machineKey>
var deckey = "FFA87B82D4A1BEAA15C06F6434A7EB2251976A838784E134900E6629B9F954B7";


var crypto = require('crypto');

var ivc = cookie, iv, cipherText, ivSize = 16, res = "";

ivc = new Buffer(ivc, 'hex');
iv = new Buffer(ivSize);
cipherText = new Buffer(ivc.length - ivSize);
ivc.copy(iv, 0, 0, ivSize);
ivc.copy(cipherText, 0, ivSize);

c = crypto.createDecipheriv('aes-256-cbc', hex2a(deckey), iv.toString('binary'));
res = c.update(cipherText, "binary", "utf8");
res += c.final('utf8');


console.log(res);

In diesem Q & A, es werden Unterschiede zu den Versionen von Node J erwähnt. Ich habe versucht, diese anzuwenden, aber ohne Erfolg:

res = c.update(cipherText, "binary", "utf8");

line Ergebnis wie Ergebnis

�sJ舸=�X7D������G����}x���T

un

res += c.final('utf8'); 

gibt diesen Fehler

0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length

nodejs Version: 4.1.2 und Crypto Version 0.0.3

Wie kann ich Cookies mit diesem Algorithmus richtig entschlüsseln oder können Sie einen anderen vorschlagen?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage