SecureJS is a modern JavaScript cryptography library designed to enhance web application security. It provides a user-friendly interface for complex cryptographic operations using advanced encryption algorithms.
- AES-GCM Encryption: Secure symmetric encryption for data confidentiality and integrity.
- ECDSA Digital Signatures: Robust asymmetric encryption for authentication and non-repudiation.
- Argon2 Password Hashing: State-of-the-art password hashing (server-side only).
- Cross-Environment Compatibility: Works in both browser and Node.js environments.
npm install @todak2000/securejs
import { SecureJS } from "@todak2000/securejs";
const key = await SecureJS.generateEncryptionKey();
const encryptedMessage = await SecureJS.encrypt("Sensitive data", key);
const decryptedMessage = await SecureJS.decrypt(encryptedMessage, key);
console.log(decryptedMessage); // Output: "Sensitive data"
const keyPair = await SecureJS.generateKeyPair();
const messageBuffer = new TextEncoder().encode("Verify me!");
const signature = await SecureJS.sign(messageBuffer, keyPair.privateKey);
const isValid = await SecureJS.verify(signature, messageBuffer, keyPair.publicKey);
console.log(isValid); // Output: true
const hashedPassword = await SecureJS.hash("mySecretPassword");
const isMatch = await SecureJS.verify("mySecretPassword", hashedPassword);
console.log(isMatch); // Output: true
-
generateEncryptionKey()
: Generates a secure encryption key. -
encrypt(data, key)
: Encrypts data using AES-GCM. -
decrypt(encryptedData, key)
: Decrypts AES-GCM encrypted data.
-
generateKeyPair()
: Generates a public-private key pair for ECDSA. -
sign(data, privateKey)
: Signs data with a private key. -
verify(signature, data, publicKey)
: Verifies a signature with a public key.
-
hash(data)
: Hashes data using Argon2. -
verify(plaintext, hashedData)
: Verifies hashed data against plaintext.
- Always use HTTPS when transmitting encrypted data or keys.
- Never store encryption keys or private keys in client-side storage.
- Argon2 hashing is only available server-side due to browser limitations.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.