<?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: slavas-dev</title>
    <description>The latest articles on DEV Community by slavas-dev (@slavasdev).</description>
    <link>https://dev.to/slavasdev</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%2F4001248%2Fdc92abe1-a6a9-4373-b8b1-9fe7628e53a3.png</url>
      <title>DEV Community: slavas-dev</title>
      <link>https://dev.to/slavasdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/slavasdev"/>
    <language>en</language>
    <item>
      <title>How I built an end-to-end encrypted pastebin (and why the server can’t read your text)</title>
      <dc:creator>slavas-dev</dc:creator>
      <pubDate>Wed, 24 Jun 2026 21:35:58 +0000</pubDate>
      <link>https://dev.to/slavasdev/how-i-built-an-end-to-end-encrypted-pastebin-and-why-the-server-cant-read-your-text-8jj</link>
      <guid>https://dev.to/slavasdev/how-i-built-an-end-to-end-encrypted-pastebin-and-why-the-server-cant-read-your-text-8jj</guid>
      <description>&lt;p&gt;got annoyed that pastebin and similar sites log everything and keep your text forever, so i built one where the server literally cant read what you paste. heres how the encryption actually works and what i learned building it&lt;/p&gt;

&lt;h2&gt;
  
  
  the problem
&lt;/h2&gt;

&lt;p&gt;most paste sites work like this: you type something, it goes to their server as plain text, and it sits in their database. they can read it. their employees can read it. anyone who breaches them can read it. and a lot of them keep it forever even after you think its gone.&lt;/p&gt;

&lt;p&gt;i didnt want to just &lt;em&gt;promise&lt;/em&gt; not to look at your stuff. i wanted it so that i &lt;em&gt;cant&lt;/em&gt; look even if i wanted to.&lt;/p&gt;

&lt;h2&gt;
  
  
  the idea: encrypt before it leaves the browser
&lt;/h2&gt;

&lt;p&gt;the trick is that all the encryption happens on your side, in the browser, before anything gets sent. the server only ever sees scrambled bytes. the key never touches the server at all, it lives in the part of the url after the &lt;code&gt;#&lt;/code&gt;, which browsers dont send in requests.&lt;/p&gt;

&lt;p&gt;so the flow is basically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;you paste text&lt;/li&gt;
&lt;li&gt;browser generates a random key&lt;/li&gt;
&lt;li&gt;text gets encrypted with that key&lt;/li&gt;
&lt;li&gt;only the encrypted blob goes to the server&lt;/li&gt;
&lt;li&gt;the key gets stuck in the link after a &lt;code&gt;#&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;whoever opens the link decrypts it locally&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  the actual code
&lt;/h2&gt;

&lt;p&gt;modern browsers have the Web Crypto API built in, so you dont need any library for this. heres the encrypt part, stripped down:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;\&lt;/code&gt;`js&lt;br&gt;
async function encrypt(text) {&lt;br&gt;
  const key = await crypto.subtle.generateKey(&lt;br&gt;
    { name: "AES-GCM", length: 256 },&lt;br&gt;
    true,&lt;br&gt;
    ["encrypt", "decrypt"]&lt;br&gt;
  );&lt;/p&gt;

&lt;p&gt;const iv = crypto.getRandomValues(new Uint8Array(12));&lt;br&gt;
  const encoded = new TextEncoder().encode(text);&lt;/p&gt;

&lt;p&gt;const ciphertext = await crypto.subtle.encrypt(&lt;br&gt;
    { name: "AES-GCM", iv },&lt;br&gt;
    key,&lt;br&gt;
    encoded&lt;br&gt;
  );&lt;/p&gt;

&lt;p&gt;// export the key so we can put it in the url&lt;br&gt;
  const rawKey = await crypto.subtle.exportKey("raw", key);&lt;/p&gt;

&lt;p&gt;return { ciphertext, iv, rawKey };&lt;br&gt;
}&lt;br&gt;
`&lt;code&gt;\&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;the ciphertext and iv go to the server. the &lt;code&gt;rawKey&lt;/code&gt; gets base64'd and dropped into the link after the &lt;code&gt;#&lt;/code&gt;. decrypting is just the same thing in reverse with &lt;code&gt;crypto.subtle.decrypt&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  the thing that tripped me up
&lt;/h2&gt;

&lt;p&gt;the &lt;code&gt;#&lt;/code&gt; part of a url (the fragment) never gets sent to the server. thats the whole reason this works, the key stays client side. but it also means if you log requests anywhere, you have to be careful you arent accidentally capturing the full url somewhere on the client and shipping it off. took me a bit to convince myself nothing was leaking it.&lt;/p&gt;

&lt;p&gt;also: burn after read is harder than it sounds. you have to delete on the server the moment its read, but handle the race where two people open the link at the same time. i settled on deleting on first successful fetch and just letting the second person get a 404.&lt;/p&gt;

&lt;h2&gt;
  
  
  anyway
&lt;/h2&gt;

&lt;p&gt;ended up turning it into a small thing you can actually use: &lt;a href="https://hidetext.sh" rel="noopener noreferrer"&gt;hidetext.sh&lt;/a&gt;. no accounts, no tracking, optional burn after read, and it does files and qr codes too.&lt;/p&gt;

&lt;p&gt;curious how other people have handled the burn-after-read race condition though, if youve built something similar lmk&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>security</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
