easecrypto

1.0.2 • Public • Published

Easecrypto package

A package to help you encrypt/decrypt files and strings with simple functions

Installation

Install via npm

    $ npm install easecrypto

How to use

import the functions you need

    const {fileEncryptor, fileDecryptor, keyEncryptor, keyDecryptor} = require('easecrypto')

Functions

File Encryptor

Example

    fileEncryptor('./src.json', './dist.ms', privateKey,'r', ((data, err) => {
        if(err){
            console.error(err);
        }else{
            console.log(data);
        }
    }))

Functions parameters

  • 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.

Troubleshooting

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);
        }
    }))

File Decryptor

Example

    fileDecryptor('./dist.ms', './new.json', privateKey, (res => {
        console.log(res);
    }))

Functions parameters

  • 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

Troubleshooting

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);
    }))

Key Encryptor

Example

    const encryptedKey = keyEncryptor("secret password", privateKey)

Functions parameters

  • key the string value to encrypt
  • encryption key private key to encrypt the text and decrypt it

Key Decryptor

Example

    const decryptedKey = keyDecryptor(encryptedKey, privateKey)

Functions parameters

  • encrypted key the encrypted string value to decrypt
  • encryption key private key to encrypt the text and decrypt it

Package Sidebar

Install

npm i easecrypto

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

13.8 kB

Total Files

5

Last publish

Collaborators

  • medostudios