mirror of
				https://github.com/mickael-kerjean/filestash.git
				synced 2025-11-04 13:35:46 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			14 lines
		
	
	
		
			430 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			14 lines
		
	
	
		
			430 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import crypto from 'crypto';
 | 
						|
const algorithm = 'aes-256-cbc';
 | 
						|
 | 
						|
export function encrypt(obj, key){
 | 
						|
    const cipher = crypto.createCipher(algorithm, key);
 | 
						|
    return cipher.update(JSON.stringify(obj), 'utf8', 'base64') + cipher.final('base64');
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
export function decrypt(text, key){
 | 
						|
    var decipher = crypto.createDecipher(algorithm, key)
 | 
						|
    return JSON.parse(decipher.update(text,'base64','utf8') + decipher.final('utf8'));
 | 
						|
}
 |