我在我的应用程序的生产实例中遇到了 node.js 的加密模块的问题,
当我在 Amazon 实例中使用“pbkdf2Sync”函数时,它的效果很糟糕,并且对于相同的值集返回不同的值。
我制作了一个小脚本来查看问题:
var crypto = require('crypto');
var len = 128;
var iterations = 12000;
console.log(new Buffer(crypto.pbkdf2Sync('lalala','lalala', iterations, len), 'binary').toString('base64'));
console.log(new Buffer(crypto.pbkdf2Sync('lalala','lalala', iterations, len), 'binary').toString('base64'));
在我的开发机器上返回(A MacBook Air):
g3hfqNL+32Z8HfkF+2o/x1IT4HclmpBB4VeYEt+9k7gaN+HO4J3vwIyMMcPej21KkGuBvAbjjsw5N4kWZEHA/Dq8yL3P5lPwHTCzt+MVJcSA85MrjMY72SHU7TGLpXAzHhkE6S+xNRlL/4fGQu9oBgAvAIP7ar/JOj1y3tAghP4=
g3hfqNL+32Z8HfkF+2o/x1IT4HclmpBB4VeYEt+9k7gaN+HO4J3vwIyMMcPej21KkGuBvAbjjsw5N4kWZEHA/Dq8yL3P5lPwHTCzt+MVJcSA85MrjMY72SHU7TGLpXAzHhkE6S+xNRlL/4fGQu9oBgAvAIP7ar/JOj1y3tAghP4=
但在生产机器(Amazon EC2-medium 实例)中:
AAAHAAAAAQAAAAAAAAAAAAAAoK3iaSkVAAAAAAAAAQAAADlBcJs9DQAAAAAAAAEAAABZcvIWqQAAAKCiMgL/fwAAAAAAAAAAAADIojIC/38AAAAAAAAHAAAAOXPyFqkAAAAQozIC/38AAEIL5GkpFQAAAAAAAAAAAABhIQAAAAA=
yAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAConjIC/38AAABiyQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPBdyQIAAAAAAAA=
我不知道为什么会这样,这是 node.js 加密模块的错误?