Skip to content

Latest commit

 

History

History

scryptify

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

scryptify

A stronger encryption and decryption in Node.js


MIT License

A stronger encryption and description in Node.js based on implementation that can be found here Stronger Encryption and Decryption in Node.js | Vance Lucas.

In short, a strong encryption will always produce a unique output and it will always return the raw data after the decryption. A 256 bytes (or 32 characters) salt is needed to do the encryption and decryption process. This salt can be generated by making use of one of the great NPM modules that is available out there - randomstring.

Table of contents

Usage

import randomstring from 'randomstring';

import { encrypt, decrypt } from 'nodemod/dist/scryptify/index.js';

(async () => {
  /** 256 bytes or 32 characters salt */
  const secret = randomstring.generate(32);

  const rawData = '5ome_rand0m_m3ss4g3';
  const encrypted = await encrypt(rawData, secret);
  const decrypted = await decrypt(encrypted, secret);

  decrypted === rawData; /** true */
})();

API Reference

encrypt(text, secret)

  • text <string> Input string to be encrypted.
  • secret <string> A 256 bytes (or 32 characters) salt for the encryption.
  • returns: <Promise<string>> Promise which resolves with an encrypted output.

encryptSync(text, secret)

This methods works the same as encrypt(text, secret) except that this is the synchronous version.

decrypt(text, secret)

  • text <string> Encrypted input string.
  • secret <string> A 256 bytes (or 32 characters) salt for the decryption. This must be the exact same salt that is used in encrypting the input string.
  • returns: <Promise<string>> Promise which resolves with the raw content of the encrypted data.

decryptSync(text, secret)

This methods works the same as decrypt(text, secret) except that this is the synchronous version.

License

MIT License © Rong Sen Ng