Created
July 26, 2011 10:18
-
-
Save erikdubbelboer/1106441 to your computer and use it in GitHub Desktop.
Nodejs base64 crypto bug?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
var origtoken = '128073137281613|2.AQDnAjjO73ESnmhJ.3611.1311634811.2-3306278|i3L2dgZ7rg6m2vKt0GzjhhKbzTQ'; | |
var algo = 'des-ecb'; // openssl list-cipher-commands to list available algos | |
var key = 'appelsap'; | |
var base = 'base64'; // changing this to 'hex' makes it work | |
var tokencrypt = crypto.createCipher(algo, key); | |
var token = tokencrypt.update(origtoken, 'ascii', base)+tokencrypt.final(base); | |
//console.log(token); | |
tokencrypt = crypto.createDecipher(algo, key); | |
token = tokencrypt.update(token, base, 'ascii')+tokencrypt.final('ascii'); | |
console.log(token); | |
console.log(origtoken); | |
// Prints: | |
//128073137281613|2.AQDnAjjO73ESnmhJ.3611.1311634811.2-3306278|i3L2dgZ7rg6m2vKt0GzZ ���´J | |
//128073137281613|2.AQDnAjjO73ESnmhJ.3611.1311634811.2-3306278|i3L2dgZ7rg6m2vKt0GzjhhKbzTQ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment