New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

easy-nodecrypt

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-nodecrypt

A simple nodejs library that makes life easier when you want to encrypt and decrypt string to multiple encodings.

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NodeCrypt

A simple nodejs library that makes life easier when you want to encrypt and decrypt string to multiple encodings.

This library was written in pure NodeJS with TypeScript.

How to use

  • With IV

    Create a new instance of NodeCryptIV

    const NodeCryptIV = require('easy-nodecrypt').NodeCryptIV;
    
    • Random mode

      const nodeCryptIV = new NodeCryptIV({ secret: 'mysecret' });
      const encrypted = nodeCryptIV.encrypt('Pika Pika!').toBase64();
      console.log(encrypted); // emlSWvnh7cUwkEvWWeZafcR3Kp8YJafoRoJvJBQ_t38
      
      const decrypted = nodeCryptIV.decrypt(encrypted);
      console.log(decrypted); // Pika Pika!
      
    • No random mode

      You can give the IV with an environment variable (NODECRYPT_IV) or directly in the NodeCryptIV instance. The function use first the IV in parameter and if it's not exist, it use the environment variable.

      The IV must have a length of 16 characters.

      const nodeCryptIV = new NodeCryptIV({ secret: 'mysecret', iv: 'totototototototo' });
      const encrypted = nodeCryptIV.encrypt('Pika Pika!').toBase64();
      console.log(encrypted); // dG90b3RvdG90b3RvdG90b8bCKJ7SMuOaSWvijqvujXM
      
      const decrypted = nodeCryptIV.decrypt(encrypted);
      console.log(decrypted); // Pika Pika!
      
  • Without IV

    Create a new instance of NodeCrypt

    const NodeCrypt = require('easy-nodecrypt').NodeCrypt;
    
    const nodeCrypt = new NodeCrypt('mysecret');
    const encrypted = nodeCrypt.encrypt('Pika Pika!').toBase64();
    console.log(encrypted); // spsAgpAHVSClkOKb0LTT8Q
    
    const decrypted = nodeCrypt.decrypt(encrypted);
    console.log(decrypted); // Pika Pika!
    

Tips and trikcs

  • If you want to decrypt a value with another instance of the library, don't forget to specify the encoding to use:
    // Encrypt value.
    const nodeCrypt = new NodeCrypt('mysecret');
    const encrypted = nodeCrypt.encrypt('Pika Pika!').toBase64();
    
    // Decrypt value with the same instance.
    const decrypted = nodeCrypt.decrypt(encrypted);
    
    // Decrypt value with another instance.
    const newInstance = new NodeCrypt('mysecret');
    // Specify the encoding of the encrypted text.
    newInstance.encoding = 'base64';
    newInstance.decrypt(encrypted);
    

Environements variables

You can give the above values by environements variables:

Environement variableCode variableClass
NODECRYPT_SECRETsecretNodeCrypt, NodeCryptIV
NODECRYPT_IVivNodeCryptIV

Author

Guillaume Quittet

https://www.linkedin.com/in/gquittet/

Give me a coffee ☕

https://paypal.me/gquittet

Keywords

FAQs

Package last updated on 03 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc