encryptionpackage
Advanced tools
Comparing version 1.0.2 to 1.0.3
// encryption.js | ||
// Helper function to derive a key from a passphrase | ||
async function deriveKey(passphrase) { | ||
async function deriveKey(passphrase, salt) { | ||
const encoder = new TextEncoder(); | ||
@@ -18,3 +18,3 @@ const keyMaterial = await crypto.subtle.importKey( | ||
name: 'PBKDF2', | ||
salt: crypto.getRandomValues(new Uint8Array(16)), // Random salt for security | ||
salt: salt, // Use the provided salt for key derivation | ||
iterations: 100000, | ||
@@ -35,4 +35,6 @@ hash: 'SHA-256' | ||
const encoder = new TextEncoder(); | ||
const cryptoKey = await deriveKey(passphrase); // Derive key from passphrase | ||
const salt = crypto.getRandomValues(new Uint8Array(16)); // Generate random salt | ||
const cryptoKey = await deriveKey(passphrase, salt); // Derive key from passphrase and salt | ||
const iv = crypto.getRandomValues(new Uint8Array(16)); // Generate random IV | ||
@@ -48,2 +50,3 @@ | ||
return { | ||
salt: Array.from(salt), // Store the salt with the encrypted data | ||
iv: Array.from(iv), // Convert to array for easy storage | ||
@@ -57,3 +60,4 @@ content: Array.from(new Uint8Array(encrypted)) // Convert to array | ||
const decoder = new TextDecoder(); | ||
const cryptoKey = await deriveKey(passphrase); // Derive key from passphrase | ||
const salt = new Uint8Array(encryptedData.salt); // Retrieve the salt | ||
const cryptoKey = await deriveKey(passphrase, salt); // Derive key from passphrase and salt | ||
@@ -60,0 +64,0 @@ const iv = new Uint8Array(encryptedData.iv); |
{ | ||
"name": "encryptionpackage", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"main": "encryption.js", | ||
@@ -5,0 +5,0 @@ "module": "encryption.js", |
Sorry, the diff of this file is not supported yet
65
3643