A package to help you encrypt/decrypt files and strings with simple functions
Install via npm
$ npm install easecrypto
import the functions you need
const {fileEncryptor, fileDecryptor, keyEncryptor, keyDecryptor} = require('easecrypto')
fileEncryptor('./src.json', './dist.ms', privateKey,'r', ((data, err) => {
if(err){
console.error(err);
}else{
console.log(data);
}
}))
- source path the path of the file to encrypt
- destination path the path, name and extension of the created file
- encryption key private key to encrypt the file and decrypt it
- flag null or 'r' If the destination file already exists, the encryption will stop and returns an error. However, if you wont to overwrite it pass 'r' into the parameter.
- callback this function is asynchronous. the callback contains err and success message to make sure the process went fine.
make sure you pass the flag parameter! pass 'r' or null. Otherwise it will throw an error.
fileEncryptor('./src.json', './dist.ms', privateKey,null, ((data, err) => {
if(err){
console.error(err);
}else{
console.log(data);
}
}))
fileDecryptor('./dist.ms', './new.json', privateKey, (res => {
console.log(res);
}))
- source path the path of the file to decrypt
- destination path null or path the path, name and extension of the created file. if the value is null. the callback res will return the content without writing a file to include the data.
- encryption key private key to encrypt the file and decrypt it
- callback this function is asynchronous. the callback contains a success message or the content of the file if destination file is set to null
make sure you pass the destination path parameter! either a path value or null. Otherwise it will throw an error.
fileDecryptor('./dist.ms', null, privateKey, (res => {
console.log(res);
}))
const encryptedKey = keyEncryptor("secret password", privateKey)
- key the string value to encrypt
- encryption key private key to encrypt the text and decrypt it
const decryptedKey = keyDecryptor(encryptedKey, privateKey)
- encrypted key the encrypted string value to decrypt
- encryption key private key to encrypt the text and decrypt it