bxor-crypt v1.0.0
bxor-crypt
bxor-crypt
is a Node.JS library that provides a simple but secure API for encrypting and decrypting string and files. It supports every type of file, either a plain text one and a binary file. The encrypted result is a base64 string that can be stored safely everywhere.
Installation
bxor-crypt
is a npm module. It can be installed with this command:
$ npm install bxor-crypt
Usage
A simple example on encrypting a string and its expected output:
const bx = require("bxor-crypt");
console.log(bx.encrypt("ABCdefGHIjkl", "password"));
// Will output "jpyPqK22ipOGtKeg"
console.log(bx.decrypt("jpyPqK22ipOGtKeg", "password"));
// Will output "ABCdefGHIjkl"
Headers
To check if the string was decrypted succesfully, bxor-crypt
implements headers. When encrypting, a header can be specified. It will be checked later during decryption. If the header isn't present or is incorrect, it will raise an error. This is useful for checking the integrity and if the provided password is correct.
Methods
encrypt(str, salt, header, xrn)
str
: The string to encryptsalt
: The "password" or salt used to encrypt the stringheader
: The header to use. Leave empty to not use anyxrn
: A value used during encryption to apply the bitwise XOR. Default to 191, but can be set to any
decrypt(str, salt, header, xrn)
str
: The string to decryptsalt
: The "password" or salt used to decrypt the stringheader
: The header to check. Leave empty to not check anyxrn
: A value used during decryption to apply the bitwise XOR
encryptFile(input, output, salt, header, xrn)
input
: A file or a path to a file. Represents the file that will be encryptedoutput
: The file or the path to the file where the encrypted file will be savedsalt
: The "password" or salt used to encrypt the fileheader
: The header to use. Leave empty to not use anyxrn
: A value used during encryption to apply the bitwise XOR
decryptFile(input, output, salt, header, xrn)
input
: A file or a path to a file. Represents the file that will be decryptedoutput
: The file or the path to the file where the decrypted file will be savedsalt
: The "password" or salt used to decrypt the fileheader
: The header to check. Leave empty to not check anyxrn
: A value used during decryption to apply the bitwise XOR
License
This project is licensed under the MIT license. It can be checked online here or in the LICENSE
file in this repository.
Contributing
Contributing to this project is welcome. If you find any bug, want to improve the project or just want to give feedback, do it at the main project repo. Every help is welcome and appreciated.
5 years ago