Package Exports
- wcipher
- wcipher/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wcipher) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
WCipher
WCipher is a TypeScript library that leverages the native Web Crypto API for robust and secure encryption and decryption. Designed with ease of use in mind, it offers seamless integration into your applications while ensuring top-notch security.
Features
- Password-Based Key Derivation: Encryption keys are derived securely from user-provided passwords using the PBKDF2 (Password-Based Key Derivation Function 2) algorithm.
- AES-GCM Encryption: Plain data is encrypted using the AES-GCM (Advanced Encryption Standard - Galois/Counter Mode) algorithm, providing both confidentiality and integrity.
- Comprehensive Encryption Result: The final encryption output includes the key salt, initialization vector (IV), and encrypted data, all combined into a single package for convenience and security.
Data Structure
The combined encrypted content contains:
- 16 bytes of key salt, generated by using
crypto.getRandomValues - 12 bytes of initialization vector (IV), generated by using
crypto.getRandomValues - Variable length of encrypted data + AES Auth Tags
Example 1: Encryption
// Import library
import WCipher from "wcipher";
// Convert plain text to byte array
const plainTextData = "Plain text data...";
const plainTextBytes = new TextEncoder().encode(plainTextData);
// Encrypt data
const encryptedData = await WCipher.encrypt(
"A_SUper-Strong!P@ssw0rd", plainTextBytes);Example 2: Decryption
// Import library
import WCipher from "wcipher";
// Convert plain text to byte array
const encryptedData = /* Prepare the encrypted data in Uint8Array */;
// Decrypt data
const originalData = await WCipher.decrypt(
"A_SUper-Strong!P@ssw0rd", encryptedData);
// Optional: If the original data is text,
// convert the data back to text by using TextDecoder.
const plainTextData = new TextDecoder().decode(originalData);
console.log("Original text: " + plainTextData);License
Licensed under the MIT license.