import crypto from "crypto" ; import { AesKey } from "./aes-key" ; param key param buffer export function aesEncrypt ( { key , buffer } ) { const cipher = crypto . createCipher ( "aes256" , key ) ; let result = cipher . update ( buffer ) ; result = Buffer . concat ( [ result , cipher . final ( ) ] ) ; return result ; } param key param buffer export function aesDecrypt ( { key , buffer } ) { const decipher = crypto . createDecipher ( "aes256" , key ) ; let result = decipher . update ( buffer ) ; result = Buffer . concat ( [ result , decipher . final ( ) ] ) ; return result ; } param passphrase param salt export function createAesKey ( { passphrase , salt } ) { if ( ! salt ) { salt = crypto . randomBytes ( 16 ) ; } const key = crypto . pbkdf2Sync ( passphrase , salt , 100000 , 128 , "sha512" ) ; return { key , salt , } ; }