
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
crypto-shield
Advanced tools
CryptoShield is a powerful and efficient Node.js library designed for seamless encryption and decryption using a variety of algorithms. Leveraging Node.js's built-in crypto module, this library empowers users with fine-grained control over their encryptio
crypto-shield: Secure and Efficient Encryption and Decryption Library for Node.js
crypto-shield is a powerful and efficient Node.js library designed for seamless encryption and decryption using a variety of algorithms. Leveraging Node.js's built-in crypto module, this library empowers users with fine-grained control over their encryption processes, ensuring both security and flexibility.
string
>
string
>
boolean
>
boolean
>
crypto-shield provides an extensive feature set to meet your encryption and decryption needs while offering simplicity, security, and flexibility in your Node.js projects.
Install the package using npm:
npm install crypto-shield
Install the package using yarn:
yarn add crypto-shield
Install the package using bun:
bun add crypto-shield
// CommonJS
const CryptoShield = require("crypto-shield");
const encryptor = new CryptoShield();
// ESM
import CryptoShield from "crypto-shield";
const encryptor = new CryptoShield();
const secretKey = "my-secret-key";
// Set the key while initialize
const encryptor = new CryptoShield({ secretKey });
// OR
// Add secretKey after initialize it.
const encryptor = new CryptoShield();
encryptor.setSecretKey(secretKey);
const plaintext = "Hello, world!";
// Async/Await
(async () => {
try {
const encryptedText = await encryptor.encryptText(plaintext);
console.log("Encrypted Text:", encryptedText); // 3992b5bf64591ebbe93708ffb2dc00e8a481b93d4c2c1b752509525b05a4f24316a9d3e82556e61e79c6c129db31b62cf57a910a3c3b1d0d64ab0dc41a4eaa5ce948442365d2ce0280
const decryptedText = await encryptor.decryptText(encryptedText);
console.log("Decrypted Text:", decryptedText); // Hello, world!
} catch (error) {
console.error("Error:", error);
}
})();
// Promises
encryptor
.encryptText(plaintext)
.then((encryptedText) => {
console.log("Encrypted Text:", encryptedText);
return encryptor.decryptText(encryptedText);
})
.then((decryptedText) => {
console.log("Decrypted Text:", decryptedText);
})
.catch((error) => {
console.error("Error:", error);
});
const inputFile = "input.txt";
const outputFile = "output.txt";
const secretKey = "my-secret-key";
encryptor.setSecretKey(secretKey);
// Async/Await
(async () => {
try {
await encryptor.encryptFile(inputFile, outputFile);
console.log("File encrypted successfully");
await encryptor.decryptFile(outputFile);
console.log("File decrypted successfully");
} catch (error) {
console.error("Error:", error);
}
})();
// Promises
encryptor
.encryptFile(inputFile, outputFile)
.then(() => console.log("File encrypted successfully"))
.then(() => encryptor.decryptFile(outputFile))
.then(() => console.log("File decrypted successfully"))
.catch((error) => console.error("Error:", error));
Creates an instance of the CryptoShield class.
options
(optional): EncryptDecryptOptions
- An object with configuration options.The EncryptDecryptOptions
interface defines the configuration options available when initializing an instance of the CryptoShield
class.
algorithm
(optional): Specifies the encryption algorithm to be used. Choose from the supported algorithms defined in EncryptionAlgorithm
. Default is "aes-256-gcm"
.
iterations
(optional): The number of iterations for the key derivation function (PBKDF2). Default is 5000
.
keyLength
(optional): The length of the encryption key. Choose from the common key lengths defined in KeyLength
. Default is 32
.
ivLength
(optional): The length of the initialization vector (IV) used in the encryption process. Default is 12
.
tagLength
(optional): The length of the authentication tag used in some encryption algorithms. Choose from AuthTagLength
. Default is 16
.
salt
(optional): The length of the salt used in the key derivation process. Default is 32
.
encoding
(optional): The encoding to be used for text representation. Default is "hex"
.
decoding
(optional): The encoding to be used for text decoding. Default is "utf8"
.
secretKey
(optional): The secret key used for encryption and decryption. If not provided, it can be set later using the setSecretKey
method.
pbkdf2Algorithm
(optional): The hash algorithm used in the key derivation process (PBKDF2). Choose from the supported algorithms defined in Pbkdf2Algorithm
. Default is "sha512"
.
import CryptoShield, { EncryptDecryptOptions } from "crypto-shield";
// Example options
const options: EncryptDecryptOptions = {
algorithm: "aes-128-gcm",
iterations: 10000,
keyLength: 16,
ivLength: 16,
tagLength: 8,
salt: 64,
encoding: "base64",
decoding: "utf-8",
secretKey: "my-secret-key",
pbkdf2Algorithm: "sha256",
};
// Initialize CryptoShield with options
const encryptor = new CryptoShield(options);
// Use encryptor instance with the provided options
Set the secret key for encryption and decryption.
secret
(string): The secret key.string
>Encrypts the given text.
text
(string): The text to encrypt.secret
(optional, string): The secret key.string
>Decrypts the given encrypted text.
encryptedText
(string): The text to decrypt.secret
(optional, string): The secret key.boolean
>Encrypts a file.
inputFilePath
(string): The path to the input file.outputFilePath
(optional, string): The path to the output file. If not provided, the input file will be overwritten.secret
(optional, string): The secret key.boolean
>Decrypts a file.
inputFilePath
(string): The path to the input file.outputFilePath
(optional, string): The path to the output file. If not provided, the input file will be overwritten.secret
(optional, string): The secret key.This project is licensed under the MIT License.
FAQs
CryptoShield is a powerful and efficient Node.js library designed for seamless encryption and decryption using a variety of algorithms. Leveraging Node.js's built-in crypto module, this library empowers users with fine-grained control over their encryptio
We found that crypto-shield demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.