This file ( 1kB ) exceeds the allowed full mode (48 kb) size.
The editor full hight is disabled, only scrolling is allowed..
If you wish to edit a file, it is recommended to use the scroll mode as some users do not like the full height
mode, although some users like it.
const crypto = require('crypto');
const defaultAlgorithm = 'aes256';
const encrypt = (options) => {
return new Promise((resolve, reject) => {
const {data, pass} = options;
let {algorithm} = options;
if (algorithm === undefined) {
algorithm = defaultAlgorithm;
}
const cipher = crypto.createCipheriv(algorithm, pass)
let encrypted = '';
cipher.on('readable', () => {
const ondata = cipher.read();
if (ondata) {
encrypted += ondata.toString('hex');
}
});
cipher.on('end', () => {
resolve(encrypted);
});
cipher.write(data);
cipher.end();
})
}
const decrypt = (options) => {
return new Promise((resolve, reject) => {
const {data, pass} = options;
let {algorithm} = options;
if (algorithm === undefined) {
algorithm = defaultAlgorithm;
}
const iv = Buffer.alloc(16, 0);
const decipher = crypto.createDecipheriv(algorithm, pass, iv)
let decrypted = '';
decipher.on('readable', () => {
const ondata = decipher.read();
if (ondata) {
decrypted += ondata.toString('utf8');
}
});
decipher.on('end', () => {
resolve(decrypted);
});
decipher.write(data, 'hex');
decipher.end();
})
}
module.exports.encrypt = encrypt;
module.exports.decrypt = decrypt;