DEV Community

Sh Raj
Sh Raj

Posted on

EncriptorJS - JavaScript text encryption - decryption library

EncriptorJS

EncriptorJS is a JavaScript text encryption library that allows you to securely encrypt and decrypt text. It provides a simple interface to convert your text into an encrypted form and optionally add a key for additional security. Only the correct key can be used to decrypt the text, ensuring that unauthorized access is prevented.

GitHub logo SH20RAJ / EncriptorJS

EncriptorJS is a JavaScript text encryption library that allows you to securely encrypt and decrypt text. It provides a simple interface to convert your text into an encrypted form and optionally add a key for additional security. Only the correct key can be used to decrypt the text, ensuring that unauthorized access is prevented.

EncriptorJS

EncriptorJS is a JavaScript text encryption library that allows you to securely encrypt and decrypt text. It provides a simple interface to convert your text into an encrypted form and optionally add a key for additional security. Only the correct key can be used to decrypt the text, ensuring that unauthorized access is prevented.

Installation

You can use EncriptorJS by including the library in your JavaScript project or HTML file.

In a JavaScript project

  1. Download the EncriptorJS library file (encriptor.js) from the GitHub repository.
  2. Move the encriptor.js file into your project directory.
  3. In your JavaScript file, import the EncriptorJS library:
   import Encriptor from './encriptor.js';
Enter fullscreen mode Exit fullscreen mode

or Use

npm i encriptorjs
Enter fullscreen mode Exit fullscreen mode

In an HTML file

  1. Download the EncriptorJS library file (encriptor.js) from the GitHub repository or NPMJS.

  2. Move the encriptor.js file into your project directory.

  3. In your HTML file, add the following script tag:

    …
    Enter fullscreen mode Exit fullscreen mode

Installation

You can use EncriptorJS by including the library in your JavaScript project or HTML file.

In a JavaScript project

  1. Download the EncriptorJS library file (encriptor.js) from the GitHub repository.
  2. Move the encriptor.js file into your project directory.
  3. In your JavaScript file, import the EncriptorJS library:
   import Encriptor from './encriptor.js';
Enter fullscreen mode Exit fullscreen mode

or Use

npm i encriptorjs
Enter fullscreen mode Exit fullscreen mode

In an HTML file

  1. Download the EncriptorJS library file (encriptor.js) from the GitHub repository or NPMJS.
  2. Move the encriptor.js file into your project directory.
  3. In your HTML file, add the following script tag:
   <script src="encriptor.js"></script>
Enter fullscreen mode Exit fullscreen mode

or

   <script src="https://cdn.jsdelivr.net/gh/SH20RAJ/EncriptorJS@main/encriptor.min.js"></script>
Enter fullscreen mode Exit fullscreen mode

or

<script src="https://cdn.jsdelivr.net/npm/encriptorjs" defer></script>
Enter fullscreen mode Exit fullscreen mode

Usage

Once you have included the EncriptorJS library in your project, you can start encrypting and decrypting text.

Encrypting Text

To encrypt text, use the encrypt method of the Encriptor object. Here's an example:

const text = 'My name is Sh';
const key = '1234';

const encryptedText = Encriptor.encrypt(text, key);
console.log(encryptedText); // Outputs: 'Kcdew9zdYidBf'
Enter fullscreen mode Exit fullscreen mode

The encrypt method takes two parameters: the text you want to encrypt and an optional key for additional security. It is recommended to use only digits in the key parameter. It returns the encrypted text.

Decrypting Text

To decrypt the encrypted text, use the decrypt method of the Encriptor object. Here's an example:

const encryptedText = 'Kcdew9zdYidBf'; // Replace with the encrypted text
const key = '1234';
const decryptedText = Encriptor.decrypt(encryptedText, key);
console.log(decryptedText); // Outputs: 'My name is Sh'
Enter fullscreen mode Exit fullscreen mode

The decrypt method takes two parameters: the encryptedText you want to decrypt and the key used during encryption. It returns the decrypted text.

Shuffling Strings

The EncriptorJS library also provides a utility function called shuffleString that can be used to shuffle strings using a key. Here's how you can use it:

const text = 'Hello, World!';
const shuffledText = Encriptor.shuffleString(text, 42);
console.log(shuffledText); // Outputs a shuffled version of the input string
Enter fullscreen mode Exit fullscreen mode

The shuffleString function takes a text parameter as the input string and an optional key parameter used to initialize the random number generator. By using the same key, you can obtain the same shuffled result. This function can be used for encryption purposes or to shuffle strings for other applications.

Please note that the shuffleString function alone does not provide strong encryption. For secure encryption, it is recommended to use well-established encryption algorithms and libraries designed for that purpose.

Encriptor.shuffle(text) always gives different shuffled pattern.

Examples

You can find more examples in the examples directory of this repository. The examples demonstrate various use cases of the EncriptorJS library.

License

This project is licensed under the MIT License.

Feel free to copy and paste this updated version into your README.md file, which includes the Encriptor.shuffleString() function documentation.

Refrences

https://dev.to/sh20raj/creating-a-custom-javascript-function-to-shuffle-strings-with-a-key-parameter-3c8a

encriptorjs - npm

EncriptorJS is a JavaScript text encryption library that allows you to securely encrypt and decrypt text. It provides a simple interface to convert your text into an encrypted form and optionally add a key for additional security. Only the correct key can. Latest version: 1.0.0, last published: 6 months ago. Start using encriptorjs in your project by running `npm i encriptorjs`. There are no other projects in the npm registry using encriptorjs.

favicon npmjs.com

Top comments (0)