Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
secure-encrypt
Advanced tools
A package that simplifies data encryption and decryption, supporting various algorithms and providing a straightforward API for developers.
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.
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
import { encrypt, decrypt } from 'secure-encrypt';
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);
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);
Here's the documentation for file message encryption and decryption using the secure-encrypt
npm package:
To encrypt the content of a file using secure-encrypt
, follow these steps:
Import Module:
Import the encrypt
function from the secure-encrypt
package.
import { encrypt } from 'secure-encrypt';
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');
};
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);
};
Execute Encryption:
Call the encryptFile
function with the file path and the secret key.
const inputFilePath = 'input.txt';
const secretKey = 'mySecretKey';
encryptFile(inputFilePath, secretKey);
To decrypt the content of an encrypted file using secure-encrypt
, follow these steps:
Import Module:
Import the decrypt
function from the secure-encrypt
package.
import { decrypt } from 'secure-encrypt';
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);
};
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);
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.
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.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.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.
The secure-encrypt package is inspired by the need for a versatile encryption solution with a combination of different techniques.
FAQs
A package that simplifies data encryption and decryption, supporting various algorithms and providing a straightforward API for developers.
We found that secure-encrypt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.