privacy-utils-core-crypto
v0.2.1
Published
Core cryptographic primitives for privacy-utils
Maintainers
Readme
Privacy Utils Core Crypto
Core cryptographic primitives for privacy-preserving applications.
Features
- Secure Random Generation: High-quality random number generation
- Hashing Functions: SHA-256, SHA-384, SHA-512 implementations
- Message Authentication: HMAC with various hash functions
- Authenticated Encryption: AEAD with AES-GCM
- Key Derivation: PBKDF2 and HKDF implementations
- Digital Signatures: ECDSA with secp256k1 and secp384r1 curves
Installation
npm install privacy-utils-core-cryptoUsage
import { randomBytes, sha256, hmac, aesGcmEncrypt, aesGcmDecrypt, deriveKey } from 'privacy-utils-core-crypto';
// Generate random bytes
const random = randomBytes(32);
// Hash data
const hash = sha256(new Uint8Array([1, 2, 3, 4, 5]));
// Create HMAC
const key = randomBytes(32);
const mac = hmac(key, new Uint8Array([1, 2, 3, 4, 5]), 'sha256');
// Encrypt data
const plaintext = new Uint8Array([1, 2, 3, 4, 5]);
const nonce = randomBytes(12);
const encrypted = await aesGcmEncrypt(key, nonce, plaintext);
// Decrypt data
const decrypted = await aesGcmDecrypt(key, nonce, encrypted.ciphertext, encrypted.tag);
// Derive keys
const derivedKey = await deriveKey('pbkdf2', password, salt, { iterations: 100000 });API Reference
For complete API documentation, see the TypeScript definitions or visit the main repository.
License
MIT
Contributing
Contributions are welcome! Please see the main repository for contribution guidelines.
