Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

encryptionpackage

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encryptionpackage - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

48

encryption.js
// encryption.js
// Encryption using Web Crypto API
export async function encrypt(text, key) {
// Helper function to derive a key from a passphrase
async function deriveKey(passphrase) {
const encoder = new TextEncoder();
const encodedKey = encoder.encode(key);
const keyMaterial = await crypto.subtle.importKey(
'raw',
encoder.encode(passphrase),
{ name: 'PBKDF2' },
false,
['deriveBits']
);
// Generate a key from the passphrase (symmetric key)
const cryptoKey = await crypto.subtle.importKey(
'raw',
encodedKey,
// Derive a 256-bit AES key
const key = await crypto.subtle.deriveKey(
{
name: 'PBKDF2',
salt: crypto.getRandomValues(new Uint8Array(16)), // Random salt for security
iterations: 100000,
hash: 'SHA-256'
},
keyMaterial,
{ name: 'AES-CBC', length: 256 },
false,
true,
['encrypt', 'decrypt']
);
const iv = crypto.getRandomValues(new Uint8Array(16));
return key;
}
// Encryption using Web Crypto API
export async function encrypt(text, passphrase) {
const encoder = new TextEncoder();
const cryptoKey = await deriveKey(passphrase); // Derive key from passphrase
const iv = crypto.getRandomValues(new Uint8Array(16)); // Generate random IV
// Encrypt the text

@@ -33,12 +52,5 @@ const encrypted = await crypto.subtle.encrypt(

// Decryption using Web Crypto API
export async function decrypt(encryptedData, key) {
export async function decrypt(encryptedData, passphrase) {
const decoder = new TextDecoder();
const encodedKey = new TextEncoder().encode(key);
const cryptoKey = await crypto.subtle.importKey(
'raw',
encodedKey,
{ name: 'AES-CBC', length: 256 },
false,
['encrypt', 'decrypt']
);
const cryptoKey = await deriveKey(passphrase); // Derive key from passphrase

@@ -45,0 +57,0 @@ const iv = new Uint8Array(encryptedData.iv);

{
"name": "encryptionpackage",
"version": "1.0.1",
"version": "1.0.2",
"main": "encryption.js",
"module": "encryption.js",
"type": "module",
"module": "encryption.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node test.js"
},
"keywords": ["encryption", "decryption", "aes-256-cbc", "webcrypto", "browser", "cdn"],
"keywords": [
"encryption",
"decryption",
"aes-256-cbc",
"webcrypto",
"browser",
"cdn"
],
"author": "Dhwani Upadhyay",
"license": "ISC"
"license": "ISC",
"dependencies": {
"encryptionpackage": "file:"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc