我使用AES的在線工具進行encrpyt。我正在使用我的模塊進行解密。但我得到的結果不一樣。爲什麼?NodeJS aes解密不起作用
我使用的那些工具加密之一:
這是我所提供的數據:
- 這是爲了encrpyt文本:
Hello World
- 這是密碼:
12345
- 這是該工具的結果:
U2FsdGVkX19HLG+YDMe3kYl+MYwEMlnC5mK78s3rZZg=
現在,我嘗試使用節點解密它,它不給我相同的結果。但一切工作welll
var crypto = require('crypto'),
algorithm = 'aes-128-ctr',
password = '12345';
module.exports.decrypt=function(text){
var decipher = crypto.createDecipher(algorithm,password)
var dec = decipher.update(text,'base64','utf8')
dec += decipher.final('utf8');
return dec;
}
text=module.exports.decrypt('U2FsdGVkX1+OOp0KE3lv6qcKQeS/JDFPF8YhgdU131o=')
text
我試圖更改爲AES-192,並得到了相同的問題。
更新:(基於zaph響應)
這是我這裏輸入新的數據:https://www.tools4noobs.com/online_tools/encrypt/
- 鍵:ABCDEF(16個字節)的Rijndael-128。模式:CBC。編碼:十六進制。
- 這是結果:8b25e846b6a2d52ad87f38f8134906c3
我無法解密它。這裏是我的代碼:
var crypto = require('crypto'),
algorithm = 'aes-128-cbc',
password = 'abcdef';
module.exports.decrypt=function(text){
var decipher = crypto.createDecipher(algorithm,password)
var dec = decipher.update(text,'hex','utf8')
dec += decipher.final('utf8');
return dec;
}
if(!module.parent){
var text=module.exports.decrypt('8b25e846b6a2d52ad87f38f8134906c3')
console.log(text)
}
謝謝你的信息。我正在做的任何事我都無法成功解密它NodeJS。我把這些數據放在網站上:使用鍵:abcdef(16字節)Rijndael-128。模式:CBC。編碼:十六進制。這是結果:8b25e846b6a2d52ad87f38f8134906c3 – Aminadav
這是我的代碼:http://pastebin.com/MBpz1vL1我無法解密我在網站中加密的數據。爲什麼? – Aminadav
使用CBC模式,您還需要提供16字節的IV。 – zaph