npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

secure-encrypt

v1.0.12

Published

A package that simplifies data encryption and decryption, supporting various algorithms and providing a straightforward API for developers.

Downloads

348

Readme

secure-encrypt

secure-encrypt is an npm package designed for use with ES6 (JavaScript) and TypeScript, providing a versatile encryption and decryption functionality. It supports three different encryption techniques: character substitution, hexadecimal encoding, and Caesar shift. By combining these methods, secure-encrypt offers a robust and customizable encryption solution.

Installation

To install secure-encrypt in your ES6 (JavaScript) or TypeScript project, use the following npm command:

npm install secure-encrypt

or,

yarn add secure-encrypt

Usage

Importing the Module

import { encrypt, decrypt } from 'secure-encrypt';

Encrypting a Message

To encrypt a plaintext message, use the encrypt function:

const plaintext = "Hello, World!";
const secretKey = "mySecretKey";

const encryptedText = encrypt(plaintext, secretKey);
console.log("Encrypted Text:", encryptedText);

Decrypting a Message

To decrypt an encrypted message, use the decrypt function:

const encryptedText = "encryptedTextHere";
const secretKey = "mySecretKey";

const decryptedText = decrypt(encryptedText, secretKey);
console.log("Decrypted Text:", decryptedText);

File Message Encryption and Decryption

Here's the documentation for file message encryption and decryption using the secure-encrypt npm package:

File Encryption

To encrypt the content of a file using secure-encrypt, follow these steps:

  1. Import Module: Import the encrypt function from the secure-encrypt package.

    import { encrypt } from 'secure-encrypt';
  2. Read File Content: Use a function to read the text content from the file.

    const fs = require('fs');
    const readFromFile = (filePath) => {
        return fs.readFileSync(filePath, 'utf8');
    };
  3. Encrypt and Write to File: Encrypt the content obtained from the file using the encrypt function and write the encrypted text back to the file.

    const encryptFile = (filePath, secretKey) => {
        const plaintext = readFromFile(filePath);
        const encryptedText = encrypt(plaintext, secretKey);
        writeToFile(filePath, encryptedText);
        console.log('Encryption completed. Encrypted text is written to', filePath);
    };
  4. Execute Encryption: Call the encryptFile function with the file path and the secret key.

    const inputFilePath = 'input.txt';
    const secretKey = 'mySecretKey';
    encryptFile(inputFilePath, secretKey);

File Decryption

To decrypt the content of an encrypted file using secure-encrypt, follow these steps:

  1. Import Module: Import the decrypt function from the secure-encrypt package.

    import { decrypt } from 'secure-encrypt';
  2. Decrypt and Write to File: Decrypt the content obtained from the encrypted file using the decrypt function and write the decrypted text back to the file.

    const decryptFile = (filePath, secretKey) => {
        const encryptedText = readFromFile(filePath);
        const decryptedText = decrypt(encryptedText, secretKey);
        writeToFile(filePath, decryptedText);
        console.log('Decryption completed. Decrypted text is written to', filePath);
    };
  3. Execute Decryption: Call the decryptFile function with the file path and the secret key.

    const inputFilePath = 'input.txt'; // Path to the encrypted file
    const secretKey = 'mySecretKey';
    decryptFile(inputFilePath, secretKey);

Example Code:

const fs = require('fs');
const { encrypt, decrypt } = require('secure-encrypt');

// Function to read text from a file
const readFromFile = (filePath) => {
    return fs.readFileSync(filePath, 'utf8');
};

// Function to write text to a file
const writeToFile = (filePath, data) => {
    fs.writeFileSync(filePath, data, 'utf8');
};

// Function to encrypt the content of a file and overwrite it
const encryptFile = (filePath, secretKey) => {
    const plaintext = readFromFile(filePath);
    const encryptedText = encrypt(plaintext, secretKey);
    writeToFile(filePath, encryptedText);
    console.log('Encryption completed. Encrypted text is written to', filePath);
};

// Function to decrypt the content of a file and overwrite it
const decryptFile = (filePath, secretKey) => {
    const encryptedText = readFromFile(filePath);
    const decryptedText = decrypt(encryptedText, secretKey);
    writeToFile(filePath, decryptedText);
    console.log('Decryption completed. Decrypted text is written to', filePath);
};

// Input file path
const inputFilePath = 'input.txt'; // Replace 'input.txt' with the path to your file

// Secret key
const secretKey = 'mySecretKey'; // Replace 'mySecretKey' with your secret key

// Encrypt the content of the file
encryptFile(inputFilePath, secretKey);

// Decrypt the content of the file
decryptFile(inputFilePath, secretKey);

Ensure you replace 'input.txt' with the actual path to your file and 'mySecretKey' with your secret key before executing the code.

Documentation

encrypt(plaintext, secretKey) Encrypts the provided plaintext using the specified secret key.

  • plaintext (string): The text to encrypt.
  • secretKey (string): The secret key for encryption.
  • Returns: The encrypted text (base64-encoded).

decrypt(encryptedText, secretKey) Decrypts the provided encrypted text using the specified secret key.

  • encryptedText (string): The text to decrypt (base64-encoded).
  • secretKey (string): The secret key for decryption.
  • Returns: The decrypted text.

Security Considerations

  • Secret Key: Keep your secret key confidential. Avoid hardcoding it in your code and consider using environment variables for increased security.
  • Key Management: Implement secure key management practices to protect against unauthorized access.
  • Algorithm Updates: Stay informed about cryptographic best practices and algorithm updates to ensure the security of your encrypted data.

Support and Contribution

For bug reports, feature requests, or general inquiries, please create an issue on the GitHub repository.

Contributions are welcome! Fork the repository, make your changes, and submit a pull request.

Acknowledgments

The secure-encrypt package is inspired by the need for a versatile encryption solution with a combination of different techniques.