@heyhru/server-util-crypto
v0.3.0
Published
Cryptographic utilities: AES-256-GCM encryption and scrypt password hashing
Downloads
320
Readme
@heyhru/server-util-crypto
Cryptographic utilities: AES-256-GCM encryption and scrypt password hashing. Zero external dependencies — built on node:crypto.
Usage
import { encrypt, decrypt, hashPassword, verifyPassword } from "@heyhru/server-util-crypto";
// AES-256-GCM encryption (requires a 32-byte key)
const key = "your-32-byte-encryption-key-here";
const ciphertext = encrypt("sensitive data", key);
const plaintext = decrypt(ciphertext, key);
// scrypt password hashing
const hash = await hashPassword("user-password");
const isValid = await verifyPassword("user-password", hash);API
encrypt(plaintext: string, key: string): string
Encrypt a string using AES-256-GCM. Returns iv:tag:ciphertext in hex.
decrypt(ciphertext: string, key: string): string
Decrypt a string produced by encrypt().
hashPassword(password: string): Promise<string>
Hash a password using scrypt. Returns salt:hash in hex.
verifyPassword(password: string, hash: string): Promise<boolean>
Verify a password against a hash produced by hashPassword().
