mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-29 09:07:30 +08:00
18 lines
475 B
JavaScript
18 lines
475 B
JavaScript
import crypto from 'crypto';
|
|
const algorithm = 'aes-256-ctr';
|
|
|
|
export function encrypt(obj, key){
|
|
const cipher = crypto.createCipher(algorithm, key);
|
|
return cipher.update(JSON.stringify(obj), 'utf8', 'hex') + cipher.final('hex');
|
|
}
|
|
|
|
|
|
export function decrypt(text, key){
|
|
var decipher = crypto.createDecipher(algorithm, key)
|
|
try{
|
|
return JSON.parse(decipher.update(text,'hex','utf8') + decipher.final('utf8'));
|
|
}catch(err){
|
|
return {}
|
|
}
|
|
}
|