Skip to content

A utility package for encrypting and decrypting text using AES-GCM with a secret key.

Notifications You must be signed in to change notification settings

imparth7/keycipher-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

KeyCipher

keycipher is a utility package for encrypting and decrypting text using AES-GCM with a secret key. It leverages the WebCrypto API to provide secure encryption and decryption functionalities.

Installation

To install the package, run the following command:

npm install keycipher

Usage

Here’s a brief guide on how to use the keycipher package.

Importing the Package

const { encryptData, decryptData } = require('keycipher');

Encrypting Data

To encrypt a piece of text, use the encryptData function. You need to provide the plaintext and a key string.

const { encryptData } = require('keycipher');

(async () => {
    try {
        const keyString = 'your-secret-key'; // Replace with your key
        const plainText = 'This is a secret message'; // Replace with your text

        const encryptedData = await encryptData(plainText, keyString);

        console.log('Encrypted Data:', encryptedData);
    } catch (error) {
        console.error('Encryption Error:', error);
    }
})();

Decrypting Data

To decrypt data, use the decryptData function. You need to provide the encrypted data and the same key string used for encryption.

const { decryptData } = require('keycipher');

(async () => {
    try {
        const keyString = 'your-secret-key'; // Replace with your key
        const encryptedData = {
            iv: '...your IV...',
            cipherText: '...your cipherText...',
            tag: '...your tag...'
        }; // Replace with your generated encryption object

        const decryptedText = await decryptData(encryptedData, keyString);

        console.log('Decrypted Text:', decryptedText);
    } catch (error) {
        console.error('Decryption Error:', error);
    }
})();

API

encryptData(plainText, key)

Encrypts the given plaintext using the provided key string.

  • Arguments:

    • plainText (String): The text to be encrypted.
    • key (String): The key used for encryption.
  • Returns: An object containing iv, cipherText and tag.

decryptData(encryptedData, key)

Decrypts the given encrypted data using the provided key string.

  • Arguments:

    • encryptedData (Object): The encrypted data object, which includes iv, cipherText and tag.
    • key (String): The key used for decryption.
  • Returns: The decrypted text.

About the Author

keycipher is created by Parth Dudhatra (imParth), a passionate software engineer, developer advocate, and content creator known for his contributions to the tech community. He is passionate about frontend development, Python programming, open-source software, and sharing knowledge with others.

Parth is active on various social media platforms, where he shares insights, tutorials, and tips related to programming, web development, and software engineering. Parth's dedication to sharing his expertise and fostering a supportive environment for developers has earned him recognition and respect within the tech community.

Connect with Parth Dudhatra on social media:

If you have any questions, feedback, or suggestions, feel free to reach out to me on any platform!

License

This project is licensed under the ISC License.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.

Issues

If you encounter any issues, please report them on the issues page.

About

A utility package for encrypting and decrypting text using AES-GCM with a secret key.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published