<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sasiru Mindaka</title>
    <description>The latest articles on DEV Community by Sasiru Mindaka (@sasiru-mindaka).</description>
    <link>https://dev.to/sasiru-mindaka</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4124732%2F933663b4-35ef-46dd-b62d-0af985fb6caa.png</url>
      <title>DEV Community: Sasiru Mindaka</title>
      <link>https://dev.to/sasiru-mindaka</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sasiru-mindaka"/>
    <language>en</language>
    <item>
      <title>Building SecretGate: A Zero-Knowledge Ephemeral Messaging Engine with Native PHP &amp; Web Crypto API</title>
      <dc:creator>Sasiru Mindaka</dc:creator>
      <pubDate>Mon, 14 Sep 2026 15:26:20 +0000</pubDate>
      <link>https://dev.to/sasiru-mindaka/building-secretgate-a-zero-knowledge-ephemeral-messaging-engine-with-native-php-web-crypto-api-561n</link>
      <guid>https://dev.to/sasiru-mindaka/building-secretgate-a-zero-knowledge-ephemeral-messaging-engine-with-native-php-web-crypto-api-561n</guid>
      <description>&lt;p&gt;Hey DEV Community! 👋&lt;/p&gt;

&lt;p&gt;I recently launched &lt;strong&gt;SecretGate&lt;/strong&gt;—a self-hostable, zero-knowledge ephemeral messaging platform designed to eliminate server-side trust and raw data exposure. &lt;/p&gt;

&lt;p&gt;I wanted to build an alternative to traditional anonymous/ephemeral messaging tools (like NGL or Privnote) that actually guarantees privacy through math rather than a "trust us" policy.&lt;/p&gt;

&lt;p&gt;Here is a breakdown of the technical decisions, architecture, and security model behind the project.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Why Pure Native PHP &amp;amp; Zero Frameworks?
&lt;/h2&gt;

&lt;p&gt;In a world dominated by massive &lt;code&gt;node_modules&lt;/code&gt; trees and heavy framework dependencies, I intentionally built SecretGate using &lt;strong&gt;pure native PHP 8+&lt;/strong&gt;. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zero Supply Chain Risk:&lt;/strong&gt; No Composer dependencies to keep audited or updated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Minimal Audit Surface:&lt;/strong&gt; Around 10 PHP files in total that any developer can read top-to-bottom in under an hour.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Blazing Fast Performance:&lt;/strong&gt; Runs seamlessly on standard LAMP/LEMP stacks with minimal resource footprint.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔐 How Zero-Knowledge Encryption Works
&lt;/h2&gt;

&lt;p&gt;SecretGate uses &lt;strong&gt;Hybrid Client-Side Encryption&lt;/strong&gt; via the W3C &lt;strong&gt;Web Crypto API&lt;/strong&gt; (&lt;code&gt;window.crypto.subtle&lt;/code&gt;). The server acts purely as a dumb ciphertext store.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Link Creation (Recipient)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The browser generates an &lt;strong&gt;RSA-OAEP (2048-bit)&lt;/strong&gt; keypair.&lt;/li&gt;
&lt;li&gt;The private key is wrapped using an &lt;strong&gt;AES-256-GCM&lt;/strong&gt; key derived from a user password via &lt;strong&gt;PBKDF2&lt;/strong&gt; (300,000 iterations).&lt;/li&gt;
&lt;li&gt;The encrypted private key is stored locally in the browser's &lt;strong&gt;IndexedDB vault&lt;/strong&gt; and &lt;em&gt;never&lt;/em&gt; transmitted to the server.&lt;/li&gt;
&lt;li&gt;Only the &lt;strong&gt;RSA Public Key (JWK)&lt;/strong&gt; and an &lt;strong&gt;Argon2id&lt;/strong&gt; password hash are sent to the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Message Transmission (Sender)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When a sender visits a link, their browser fetches the recipient's public key.&lt;/li&gt;
&lt;li&gt;A single-use &lt;strong&gt;AES-256-GCM&lt;/strong&gt; symmetric key encrypts the payload.&lt;/li&gt;
&lt;li&gt;The AES key is then encrypted with the recipient's RSA public key.&lt;/li&gt;
&lt;li&gt;Both ciphertexts are POSTed to the backend. The server stores data it mathematically cannot read.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Message Decryption (Recipient)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The link owner unlocks their IndexedDB vault locally using their password.&lt;/li&gt;
&lt;li&gt;Decryption of the private key and subsequent message decryption happens entirely on-device inside the browser.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🛡️ Infrastructure &amp;amp; Backend Hardening
&lt;/h2&gt;

&lt;p&gt;Even though encryption happens client-side, the backend stack is fully hardened against abuse:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Database Safety:&lt;/strong&gt; 100% prepared statements via PDO MySQL (zero raw SQL concatenation).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session &amp;amp; CSRF Security:&lt;/strong&gt; Per-session CSRF tokens, strict origin matching, and &lt;code&gt;HttpOnly&lt;/code&gt;/&lt;code&gt;SameSite=Lax&lt;/code&gt; cookie flags.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Abuse Prevention:&lt;/strong&gt; Redis-backed sliding-window rate limiting (auto-falls back to file-based storage if Redis is offline) and temporary IP burning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution Isolation:&lt;/strong&gt; Apache &lt;code&gt;.htaccess&lt;/code&gt; rules restrict PHP execution strictly to entry points (&lt;code&gt;index.php&lt;/code&gt;, &lt;code&gt;api.php&lt;/code&gt;), blocking direct access to &lt;code&gt;.env&lt;/code&gt;, &lt;code&gt;.sql&lt;/code&gt;, and backend scripts.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚀 Live Demo &amp;amp; Open Source
&lt;/h2&gt;

&lt;p&gt;SecretGate is completely &lt;strong&gt;100% Open Source&lt;/strong&gt; under the &lt;strong&gt;AGPL-3.0 License&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌐 &lt;strong&gt;Live Demo:&lt;/strong&gt; &lt;a href="https://secretgate.site" rel="noopener noreferrer"&gt;secretgate.site&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💻 &lt;strong&gt;GitHub Repository:&lt;/strong&gt; &lt;a href="https://github.com/sasiru-mindaka/Secret-Gate" rel="noopener noreferrer"&gt;github.com/sasiru-mindaka/Secret-Gate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔖 &lt;strong&gt;AlternativeTo:&lt;/strong&gt; &lt;a href="https://alternativeto.net/software/secretgate/" rel="noopener noreferrer"&gt;alternativeto.net/software/secretgate&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  💬 Feedback &amp;amp; Discussion
&lt;/h3&gt;

&lt;p&gt;I’d love to get feedback from the DEV community! &lt;/p&gt;

&lt;p&gt;How do you handle client-side cryptographic key storage in your projects? Any security improvements you'd suggest for the pipeline? &lt;/p&gt;

&lt;p&gt;If you find SecretGate interesting or useful for self-hosting, dropping a ⭐ on the &lt;a href="https://github.com/sasiru-mindaka/Secret-Gate" rel="noopener noreferrer"&gt;GitHub Repo&lt;/a&gt; would mean a lot!&lt;/p&gt;

</description>
      <category>php</category>
      <category>security</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
