zetacrypt
v1.0.1
Published
A simple substitution cipher for encrypting and decrypting passwords.
Maintainers
Readme
ZetaCrypt
ZetaCrypt is a lightweight JavaScript library that implements a substitution cipher with a key-based shuffling algorithm for encrypting and decrypting passwords. It uses a custom alphabet and a pseudo-random shuffling mechanism to provide a simple yet effective way to secure sensitive data. Ideal for developers looking to add basic encryption to their Node.js applications.
Features
- Key-Based Encryption: Uses a user-provided key to generate a unique substitution map for encryption and decryption.
- Custom Alphabet: Supports a wide range of characters, including lowercase, uppercase, numbers, and special characters.
- Reversible Cipher: Ensures encrypted passwords can be decrypted back to their original form using the same key.
- No External Dependencies: Pure JavaScript implementation, making it lightweight and easy to integrate.
- Deterministic Output: The same key and input always produce the same encrypted output, ensuring consistency.
Installation
Install ZetaCrypt via npm:
npm install zetacryptUsage
Here's a quick example to get you started with ZetaCrypt:
const ZetaCrypt = require('zetacrypt');
// Initialize with a secret key
const crypt = new ZetaCrypt('mySecretKey');
// Encrypt a password
const encrypted = crypt.encryptPassword('Hello123!');
console.log('Encrypted:', encrypted); // Outputs encrypted string
// Decrypt the password
const decrypted = crypt.decryptPassword(encrypted);
console.log('Decrypted:', decrypted); // Outputs: Hello123!API Documentation
ZetaCrypt(key)
Constructor that initializes the cipher with a key.
- key (
string): The secret key used to generate the substitution map and shift for encryption/decryption.
encryptPassword(password)
Encrypts the provided password using the substitution cipher and a shift based on the key.
- password (
string): The input string to encrypt. - Returns (
string): The encrypted string. - Note: Characters not in the supported alphabet (
a-z,A-Z,0-9,!@#$%^&*()) are preserved unchanged.
decryptPassword(encryptedPassword)
Decrypts the provided encrypted password back to its original form.
- encryptedPassword (
string): The encrypted string to decrypt. - Returns (
string): The decrypted original string. - Note: Requires the same key used for encryption to correctly decrypt.
Example Use Cases
Securing User Passwords
Use ZetaCrypt to encrypt sensitive user input, such as passwords, before storing them in a database:
const ZetaCrypt = require('zetacrypt');
const crypt = new ZetaCrypt('secureKey123');
const userPassword = 'MyP@ssw0rd!';
const encryptedPassword = crypt.encryptPassword(userPassword);
// Store encryptedPassword in database
// Later, decrypt for verification
const decryptedPassword = crypt.decryptPassword(encryptedPassword);
console.log(decryptedPassword === userPassword); // trueProtecting Configuration Data
Encrypt sensitive configuration strings, such as API keys, in configuration files:
const ZetaCrypt = require('zetacrypt');
const crypt = new ZetaCrypt('configKey');
const apiKey = 'abc123xyz';
const encryptedApiKey = crypt.encryptPassword(apiKey);
// Save encryptedApiKey to config fileSupported Alphabet
ZetaCrypt uses the following character set for encryption and decryption:
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()Any character outside this set remains unchanged in the output.
Installation Notes
- Ensure you have Node.js and npm installed.
- The package has no external dependencies, making it compatible with most Node.js environments.
- Tested with Node.js versions 14.x and above.
Issues
Report bugs or suggest improvements at github.com/64bitAtomic/ZetaCrypt/issues.
