爲什麼下面的代碼拋出了一個DecipherFinal錯誤密碼 -錯誤密碼破譯
var crypto = require('crypto');
c=new Date;
x= (c.getTime()+"."+c.getMilliseconds()).toString()+".uIn";
key = 'sevsolut'
, plaintext = x
, cipher = crypto.createCipher('aes-256-cbc', key)
, decipher = crypto.createDecipher('aes-256-cbc', key);
cipher.update(plaintext, 'utf8', 'base64');
var encryptedPassword = cipher.final('base64')
decipher.update(encryptedPassword, 'base64', 'utf8');
var decryptedPassword = decipher.final('utf8');
console.log('encrypted :', encryptedPassword);
console.log('decrypted :', decryptedPassword);
'C =新Date'應'c = new Date()' – pfried 2013-04-04 08:23:30
你爲什麼要加密密碼而不是散列它們? – Mchl 2013-04-04 08:38:18
只要你不需要傳遞參數,在JS中實例化對象時@pfried括號是可選的。 – robertklep 2013-04-04 08:53:59