Replace createDecipher with createDecipheriv and add a compatibility mode for newer nodejs versions.

This commit is contained in:
Maik Marschner
2025-03-26 15:03:36 +01:00
parent ac1b554144
commit b2ae16b933
5 changed files with 76 additions and 39 deletions

View File

@@ -1,24 +1,8 @@
'use strict';
const crypto = require('crypto');
const { encrypt, decrypt } = require('../crypto/encryptDecrypt');
const Keys = require('./Keys');
const encrypt = (data, algorithm, passphrase) => {
const cipher = crypto.createCipher(algorithm, passphrase);
const encrypted = cipher.update(data, 'utf8', 'hex') + cipher.final('hex');
return Buffer.from(encrypted).toString('base64');
};
const decrypt = (data, algorithm, passphrase) => {
data = (Buffer.from(data, 'base64')).toString();
const decipher = crypto.createDecipher(algorithm, passphrase);
const decrypted = decipher.update(data, 'hex', 'utf8') + decipher.final('utf8');
return decrypted;
};
module.exports = (keysStorage, passphrase, algorithm = 'aes-256-cbc') => {
const storage = keysStorage;
const pass = passphrase;

View File

@@ -1,24 +1,9 @@
'use strict';
const crypto = require('crypto');
const { encrypt, decrypt } = require('../crypto/encryptDecrypt');
const encrypt = (data, algorithm, passphrase) => {
const cipher = crypto.createCipher(algorithm, passphrase);
const encrypted = cipher.update(data, 'utf8', 'hex') + cipher.final('hex');
return Buffer.from(encrypted).toString('base64');
};
const decrypt = (data, algorithm, passphrase) => {
data = (Buffer.from(data, 'base64')).toString();
const decipher = crypto.createDecipher(algorithm, passphrase);
const decrypted = decipher.update(data, 'hex', 'utf8') + decipher.final('utf8');
return decrypted;
};
module.exports = ({
passphrase,
algorithm = 'aes-256-cbc',
}) => ({
encrypt: data => encrypt(data, algorithm, passphrase),
module.exports = ({ passphrase, iv, algorithm = 'aes-256-cbc' }) => ({
encrypt: data => encrypt(data, algorithm, passphrase, iv),
decrypt: data => decrypt(data, algorithm, passphrase),
});