<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[codeguyakash]]></title><description><![CDATA[Hey 👋 What's up?
My name is Akash. and I'm a Frontend Developer from Delhi, India.]]></description><link>https://blog.codeguyakash.in</link><image><url>https://cdn.hashnode.com/uploads/logos/6597d9b7449cc117507bc12a/7ea4c7b8-5052-41ee-8e2e-68819c8efd17.jpg</url><title>codeguyakash</title><link>https://blog.codeguyakash.in</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 20:33:57 GMT</lastBuildDate><atom:link href="https://blog.codeguyakash.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Securely encrypting data in a Chrome Extension without sending it to a server (key management problem) ??
]]></title><description><![CDATA[I am building a Chrome extension where some user data (for example tab metadata or browsing-related information) must remain on the user’s device due to Chrome Web Store privacy policies. The extensio]]></description><link>https://blog.codeguyakash.in/securely-encrypting-data-in-a-chrome-extension-without-sending-it-to-a-server-key-management-problem</link><guid isPermaLink="true">https://blog.codeguyakash.in/securely-encrypting-data-in-a-chrome-extension-without-sending-it-to-a-server-key-management-problem</guid><category><![CDATA[chrome extension]]></category><category><![CDATA[Google]]></category><category><![CDATA[Security]]></category><category><![CDATA[chrome web store]]></category><category><![CDATA[encryption]]></category><dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator><pubDate>Wed, 04 Mar 2026 10:35:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6597d9b7449cc117507bc12a/e3cf2c62-6f80-4dd5-b1ad-9c74508bd3e9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I am building a Chrome extension where some user data (for example tab metadata or browsing-related information) must remain on the user’s device due to Chrome Web Store privacy policies. The extension is not allowed to send this data to my server.</p>
<p>Because of this restriction, I need to store the data locally using something like <a href="http://chrome.storage">chrome.storage</a> or IndexedDB. However, storing the data in plain text is not acceptable from a security perspective.</p>
<p>My current approach is to <strong>encrypt the data before storing it locally and decrypt it when needed</strong>.</p>
<p>For encryption I am using the <strong>Web Crypto API with AES-GCM</strong>, and deriving the key from a user password using <strong>PBKDF2</strong>.</p>
<p>Here is a simplified version of the encryption logic I am currently using:</p>
<pre><code class="language-javascript">Copyconst ALGO = 'AES-GCM';
const KEY_LENGTH = 256;
const IV_LENGTH = 12;

export async function deriveKey(password, salt) {
  const enc = new TextEncoder();

  const keyMaterial = await crypto.subtle.importKey(
    'raw',
    enc.encode(password),
    'PBKDF2',
    false,
    ['deriveKey']
  );

  return crypto.subtle.deriveKey(
    {
      name: 'PBKDF2',
      salt,
      iterations: 100000,
      hash: 'SHA-256'
    },
    keyMaterial,
    {
      name: ALGO,
      length: KEY_LENGTH
    },
    false,
    ['encrypt', 'decrypt']
  );
}

export async function encryptData(data, masterPassword) {
  const enc = new TextEncoder();
  const iv = crypto.getRandomValues(new Uint8Array(IV_LENGTH));
  const salt = crypto.getRandomValues(new Uint8Array(16));

  const key = await deriveKey(masterPassword, salt);

  const encryptedBuffer = await crypto.subtle.encrypt(
    { name: ALGO, iv },
    key,
    enc.encode(JSON.stringify(data))
  );

  return {
    cipher: bufferToBase64(encryptedBuffer),
    iv: bufferToBase64(iv),
    salt: bufferToBase64(salt)
  };
}

export async function decryptData(encryptedPayload, masterPassword) {
  const { cipher, iv, salt } = encryptedPayload;

  const key = await deriveKey(masterPassword, base64ToBuffer(salt));

  const decryptedBuffer = await crypto.subtle.decrypt(
    { name: ALGO, iv: base64ToBuffer(iv) },
    key,
    base64ToBuffer(cipher)
  );

  const dec = new TextDecoder();
  return JSON.parse(dec.decode(decryptedBuffer));
}

function bufferToBase64(buffer) {
  return btoa(String.fromCharCode(...new Uint8Array(buffer)));
}

function base64ToBuffer(base64) {
  return Uint8Array.from(atob(base64), c =&gt; c.charCodeAt(0));
}
</code></pre>
<p>Example usage:</p>
<pre><code class="language-javascript">Copyconst password = '1234';
const encrypted = await encryptData(plainTab, password);
</code></pre>
<p>My main concern is <strong>key management</strong>.</p>
<p>Since this is a browser extension without a backend, I cannot store a secret key on a server. At the same time, if a key is hardcoded or stored directly in the extension code, it can be extracted by inspecting the extension.</p>
<p>So my questions are:</p>
<ol>
<li><p>What is the recommended approach for encrypting sensitive data locally in a Chrome extension?</p>
</li>
<li><p>How should the encryption key be generated and managed securely if everything runs on the client side?</p>
</li>
<li><p>Is deriving the key from a user-provided master password (using PBKDF2 or similar) considered a good practice in this scenario?</p>
</li>
<li><p>Are there established patterns used by password managers or other privacy-focused extensions for this problem?</p>
</li>
</ol>
<p>I am trying to design something similar to how <strong>password managers encrypt vault data locally before storing it</strong>.</p>
<p><strong>Environment:</strong></p>
<ul>
<li><p>Chrome Extension (Manifest V3)</p>
</li>
<li><p>JavaScript</p>
</li>
<li><p>Web Crypto API</p>
</li>
<li><p>Storage via chrome.storage or IndexedDB</p>
</li>
</ul>
<p>Have you solved a similar problem in a Chrome extension or another client-only application?<br />If you have any ideas, better approaches, or security recommendations, please leave a reply or reach out to me via email codeguyakash[at]gmail[dot]com. I’d love to learn from your experience.</p>
]]></content:encoded></item><item><title><![CDATA[Understanding Express.js: Building Web Applications with Ease]]></title><description><![CDATA[What is Express.js?
Express.js is a web application framework for Node.js. If Node.js is the engine of your web server, think of Express.js as a streamlined toolkit that helps you build things quickly and easily. It handles the complexities of routin...]]></description><link>https://blog.codeguyakash.in/understanding-expressjs-building-web-applications-with-ease</link><guid isPermaLink="true">https://blog.codeguyakash.in/understanding-expressjs-building-web-applications-with-ease</guid><category><![CDATA[Node.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Express]]></category><category><![CDATA[server]]></category><category><![CDATA[localhost]]></category><category><![CDATA[Express.js]]></category><dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator><pubDate>Wed, 24 Apr 2024 13:20:42 GMT</pubDate><content:encoded><![CDATA[<p><strong>What is Express.js?</strong></p>
<p>Express.js is a web application framework for Node.js. If Node.js is the engine of your web server, think of Express.js as a streamlined toolkit that helps you build things quickly and easily. It handles the complexities of routing (mapping URLs to actions), templating (creating dynamic HTML pages), and much more, giving you a solid foundation for your web applications.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:788/1*XwUj4VC20Q8xR_EcnH9AnQ.png" alt /></p>
<p><strong>Why Use Express.js?</strong></p>
<ol>
<li><p><strong>Simplicity:</strong> Express offers a minimalist approach, giving you the freedom to structure your application the way you want.</p>
</li>
<li><p><strong>Flexibility:</strong> It works seamlessly with many other Node.js modules available, letting you pick the tools that best suit your project.</p>
</li>
<li><p><strong>Performance:</strong> Express.js is built on Node.js, giving you great performance and scalability for web apps.</p>
</li>
<li><p><strong>Popularity:</strong> Huge community support means lots of tutorials, help, and resources to learn from.</p>
</li>
</ol>
<p><strong>Core Concepts</strong></p>
<ol>
<li><p><strong>Routing:</strong> Express lets you define “routes” — these are patterns in URLs. For example</p>
</li>
<li><p>This means, that when someone visits your website’s root (‘/’), they’ll see the text “Hello from the home page!”.</p>
</li>
</ol>
<pre><code class="lang-javascript">app.get(<span class="hljs-string">'/'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
    res.send(<span class="hljs-string">'Hello from the home page!'</span>);
});
</code></pre>
<ol>
<li><strong>Middleware:</strong> Think of middleware as functions that modify incoming requests or outgoing responses. They’re like checkpoints along the route of your application. Common uses:</li>
</ol>
<p><strong><em>i). Logging requests</em></strong></p>
<p><strong><em>ii). Authentication (checking if a user is logged in)</em></strong></p>
<p><strong><em>iii). Parsing data from forms</em></strong></p>
<ol>
<li><strong>Templating Engines:</strong> Express lets you plug in templating engines (like EJS, Pug, or Handlebars) These help you create dynamic HTML pages by filling in data on the fly.</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
<span class="hljs-keyword">const</span> app = express();
<span class="hljs-keyword">const</span> port = <span class="hljs-number">3000</span>;

<span class="hljs-comment">// A route for the homepage</span>
app.get(<span class="hljs-string">'/'</span>, <span class="hljs-function">(<span class="hljs-params">req, res</span>) =&gt;</span> {
  res.send(<span class="hljs-string">'Hello, Express!'</span>);
}); 

<span class="hljs-comment">// Start listening for requests</span>
app.listen(port, <span class="hljs-function">() =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Example app listening at http://localhost:<span class="hljs-subst">${port}</span>`</span>); 
});
</code></pre>
<p><strong>Explanation</strong></p>
<ul>
<li><p>We start by bringing in the ‘express’ module.</p>
</li>
<li><p>The <code>app</code> object is our main Express application.</p>
</li>
<li><p>We define a route for the homepage (‘/’). When someone visits this route, the function sends a text response.</p>
</li>
<li><p>Finally, we start the server listening on port 3000.</p>
</li>
</ul>
<p><strong>Next Steps</strong></p>
<p>This is just a taste of Express.js! To learn more, explore:</p>
<ul>
<li><p><strong>Express.js Official Docs:</strong> The best source (<a target="_blank" href="https://expressjs.com/">https://expressjs.com/</a>)</p>
</li>
<li><p><strong>Building Routes for Different Request Types (GET, POST, etc.):</strong> Shape how your application handles user interactions.</p>
</li>
<li><p><strong>Working with Templating Engines:</strong> Make your pages dynamic.</p>
</li>
<li><p><strong>Using Middleware for Common Tasks:</strong> Add functionality at different points.</p>
</li>
</ul>
<p>#node #express #javascript #server #localhost:300 #mern</p>
]]></content:encoded></item><item><title><![CDATA[Understanding the Benefits of Parallel Processing in Node.js]]></title><description><![CDATA[Introduction
Node.js has built a reputation for its speed and efficiency in handling web requests. However, if you’ve worked with Node.js you know that its core execution operates on a single thread. This means it generally handles one task at a time...]]></description><link>https://blog.codeguyakash.in/understanding-the-benefits-of-parallel-processing-in-nodejs</link><guid isPermaLink="true">https://blog.codeguyakash.in/understanding-the-benefits-of-parallel-processing-in-nodejs</guid><category><![CDATA[#codeguyakash #node #javascript #express #mongodb #thread #non-blocking #cpu #akash ]]></category><category><![CDATA[#codeguyakash, ]]></category><category><![CDATA[#HiteshChaudhary ]]></category><dc:creator><![CDATA[Akash (codeguyakash)]]></dc:creator><pubDate>Sun, 21 Apr 2024 06:12:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1713680125436/e5f5c5f1-a854-43da-a76d-05aa6792fa24.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction"><strong>Introduction</strong></h2>
<p>Node.js has built a reputation for its speed and efficiency in handling web requests. However, if you’ve worked with Node.js you know that its core execution operates on a single thread. This means it generally handles one task at a time. So, what happens when you have tasks that take a lot of time to compute, like image processing or complex math? That’s where the ‘worker threads’ module comes to the rescue.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:766/0*NmiMu_HPiwy2RMJA.png" alt class="image--center mx-auto" /></p>
<p><strong>Understanding Single-Threaded Node.js</strong></p>
<ul>
<li><p><strong>The Event Loop:</strong> Node.js uses the famous event loop, a super-efficient manager. Think of it like a tireless receptionist. The event loop constantly checks if any tasks are waiting. If there are, it grabs one and starts processing it.</p>
</li>
<li><p><strong>Non-Blocking I/O:</strong> When Node.js needs to do things that take time (like reading a file or making a network call), it cleverly offloads these tasks to the operating system. Then, it moves on to other tasks. When the operating system finishes, it sends a message back to the event loop saying, “Hey, I’m done!” The event loop then picks up the completed task.</p>
</li>
</ul>
<p>This approach is excellent for most web applications, but what if you need raw processing power?</p>
<p><img src="https://miro.medium.com/v2/resize:fit:788/1*fdhxqVXpL2LZCvGPcOmaDQ.png" alt class="image--center mx-auto" /></p>
<p><strong>Enter Worker Threads</strong></p>
<p>Worker threads allow you to create additional threads of execution within your Node.js process. It’s like adding extra workers to your team! These threads can handle CPU-heavy tasks in parallel with your main Node.js thread.</p>
<p><strong>Key Advantages of Worker Threads</strong></p>
<ol>
<li><p><strong>Improved Performance:</strong> Break up long calculations or data manipulation into smaller jobs that can run simultaneously.</p>
</li>
<li><p><strong>Offloading Intensive Tasks:</strong> Don’t let heavy processing clog up your main thread’s ability to respond to web requests. Shift the workload to worker threads.</p>
</li>
<li><p><strong>Shared Memory:</strong> Worker threads can share data with the main thread for fast and easy communication.</p>
</li>
</ol>
<p><strong>Example: Let’s Calculate Some Primes</strong></p>
<p>Let’s say we want to find a bunch of prime numbers:</p>
<p>JavaScript</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// main.js</span>
<span class="hljs-keyword">const</span> { Worker } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'worker_threads'</span>);

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">findPrimes</span>(<span class="hljs-params">start, range</span>) </span>{
  <span class="hljs-keyword">let</span> primes = [];
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = start; i &lt; start + range; i++) {
    <span class="hljs-keyword">if</span> (isPrime(i)) primes.push(i); 
  }
  <span class="hljs-keyword">return</span> primes;
}
<span class="hljs-keyword">const</span> worker = <span class="hljs-keyword">new</span> Worker(<span class="hljs-string">'./worker.js'</span>);

worker.on(<span class="hljs-string">'message'</span>, <span class="hljs-function">(<span class="hljs-params">result</span>) =&gt;</span> {
  <span class="hljs-built_in">console</span>.log(result); 
});

worker.postMessage({ <span class="hljs-attr">start</span>: <span class="hljs-number">1000000</span>, <span class="hljs-attr">range</span>: <span class="hljs-number">2000000</span> });
</code></pre>
<p>JavaScript</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// worker.js</span>
<span class="hljs-keyword">const</span> { parentPort, workerData } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'worker_threads'</span>);
<span class="hljs-keyword">const</span> primes = findPrimes(workerData.start, workerData.range);
parentPort.postMessage(primes);
</code></pre>
<p><strong>Explanation</strong></p>
<ul>
<li><p><strong>main.js:</strong> Creates a worker thread, sends it a task to find prime numbers, and waits for results.</p>
</li>
<li><p><strong>worker.js:</strong> Calculates prime numbers, and sends them back to the main thread.</p>
</li>
</ul>
<p>Notice we don’t use typical Node.js modules like <code>http</code> or <code>fs</code> inside a worker thread, but they're fantastic for heavy calculations!</p>
<p><strong>When Should You Use Worker Threads?</strong></p>
<ul>
<li><p><strong>CPU-Intensive Tasks:</strong> Think complex math, data analysis, compression, or image/video processing.</p>
</li>
<li><p><strong>Avoiding Main Thread Blocking:</strong> Keep your main thread free to handle incoming web requests.</p>
</li>
</ul>
<p><strong>Let me know if you’d like more advanced use cases or deeper explanations. I’m happy to tailor the article further for your blog!</strong></p>
]]></content:encoded></item></channel></rss>