encryptionpackage
Advanced tools
Comparing version 1.0.3 to 1.0.4
// encryption.js | ||
// Helper function to derive a key from a passphrase | ||
async function deriveKey(passphrase, salt) { | ||
async function deriveKey(passphrase) { | ||
const encoder = new TextEncoder(); | ||
@@ -14,7 +14,7 @@ const keyMaterial = await crypto.subtle.importKey( | ||
// Derive a 256-bit AES key | ||
// Derive a 256-bit AES key with appropriate usages | ||
const key = await crypto.subtle.deriveKey( | ||
{ | ||
name: 'PBKDF2', | ||
salt: salt, // Use the provided salt for key derivation | ||
salt: crypto.getRandomValues(new Uint8Array(16)), // Random salt for security | ||
iterations: 100000, | ||
@@ -24,5 +24,5 @@ hash: 'SHA-256' | ||
keyMaterial, | ||
{ name: 'AES-CBC', length: 256 }, | ||
true, | ||
['encrypt', 'decrypt'] | ||
{ name: 'AES-CBC', length: 256 }, // Specify the key type and length | ||
true, // The key is extractable | ||
['encrypt', 'decrypt'] // Usages for the derived key | ||
); | ||
@@ -36,6 +36,4 @@ | ||
const encoder = new TextEncoder(); | ||
const salt = crypto.getRandomValues(new Uint8Array(16)); // Generate random salt | ||
const cryptoKey = await deriveKey(passphrase); // Derive key from passphrase | ||
const cryptoKey = await deriveKey(passphrase, salt); // Derive key from passphrase and salt | ||
const iv = crypto.getRandomValues(new Uint8Array(16)); // Generate random IV | ||
@@ -51,3 +49,2 @@ | ||
return { | ||
salt: Array.from(salt), // Store the salt with the encrypted data | ||
iv: Array.from(iv), // Convert to array for easy storage | ||
@@ -61,4 +58,3 @@ content: Array.from(new Uint8Array(encrypted)) // Convert to array | ||
const decoder = new TextDecoder(); | ||
const salt = new Uint8Array(encryptedData.salt); // Retrieve the salt | ||
const cryptoKey = await deriveKey(passphrase, salt); // Derive key from passphrase and salt | ||
const cryptoKey = await deriveKey(passphrase); // Derive key from passphrase | ||
@@ -65,0 +61,0 @@ const iv = new Uint8Array(encryptedData.iv); |
{ | ||
"name": "encryptionpackage", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"main": "encryption.js", | ||
@@ -5,0 +5,0 @@ "module": "encryption.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4103
62