Coder Social home page Coder Social logo

symmetrical-encryption's Introduction

Secure Symmetrical AES-256-GCM Encryption

Super simple and secure way to encrypt and decrypt data using the AES-256-GCM algorithm in Node.js. It leverages the crypto module to automatically manage cryptographic salts, initialization vectors (IVs), and keys. Ideal for applications requiring secure data storage or transmission.

Build states

Bug report · Feature request



Features

AES-256-GCM encryption for high security Automatic salt and IV generation for each encryption operation Key derivation using scrypt for added security against brute-force attacks Customizable encoding for encrypted output Easy-to-use API for encrypting and decrypting strings

Installation

npm install symmetrical-encryption

or:

yarn add symmetrical-encryption

or:

pnpm add symmetrical-encryption

or:

bun install symmetrical-encryption

Usage

Encrypting Data

To encrypt data, provide the plaintext string, your secret key, and optionally specify the output encoding (defaults to Base64).

import { encrypt } from "symmetrical-encryption"

// Prefferably stored more securely; const secretKey = process.env.SECRET_KEY
const secretKey = "your-very-secure-secret-key"

const data = "Hi mom!"

const encryptedData = encrypt(data, secretKey, { encoding: "base64" }) // option object is optional
console.log("Encrypted Data:", encryptedData) // base64 encoded string

Decrypting Data

To decrypt data, provide the encrypted string and your secret key. The function automatically extracts the salt, IV, and authentication tag from the encrypted data.

import { decrypt } from "symmetrical-encryption"

// Prefferably stored more securely; const secretKey = process.env.SECRET_KEY
const secretKey = "your-very-secure-secret-key"

const encryptedData = "..." // The output from the encrypt function

const decryptedData = decrypt(encryptedData, secretKey)
console.log("Decrypted Data:", decryptedData) // "Hi mom!"

Note

Valid encoding options are:

type ValidEncodings = "hex" | "base64" | "latin1"

License

MIT

Creating new releases

  • npx changeset
  • npx changeset version
  • commit changes to master - it will automatically create a new tag, changelog, and publish to npm

symmetrical-encryption's People

Contributors

hevar avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.