我試圖創建一個與Laravel的加密模塊兼容的散列。 這裏是Laravel參考源代碼:https://github.com/illuminate/encryption/blob/master/Encrypter.php#L101-163Compatibilty AES-256-CBC節點/ Laravel
這裏是我來過:
const encrypt = function (payload) {
const iv = crypto.randomBytes(16);
const key = new Buffer(config.stuff.key, 'base64');
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
cipher.setAutoPadding(false); // With or without this /!\
let value = cipher.update(serialize(JSON.stringify(payload)), 'utf8', 'base64');
value + cipher.final('base64');
const mac = crypto.createHmac('sha256', new Buffer(config.stuff.key, 'base64')).update(iv.toString('base64') + value).digest('hex');
const json = JSON.stringify({ iv: iv.toString('base64'), value, mac });
return base64_encode(json);
};
不幸的是,我有一個BAD_DECRYPT當我嘗試這一點。這似乎來自OpenSSL的填充。有人有想法嗎?
注意:我有base64_encode和從phpjs和其他東西序列化函數實用程序 – Extaze