<?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: Anh Phan</title>
    <description>The latest articles on DEV Community by Anh Phan (@anhp9669).</description>
    <link>https://dev.to/anhp9669</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F331512%2F2c0e5dff-cc73-4392-8e6a-d6df8024bd1e.jpg</url>
      <title>DEV Community: Anh Phan</title>
      <link>https://dev.to/anhp9669</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anhp9669"/>
    <language>en</language>
    <item>
      <title>Inside the Money Flow in Centralized Exchanges: MPC + TEE at Work</title>
      <dc:creator>Anh Phan</dc:creator>
      <pubDate>Fri, 25 Jul 2025 08:12:11 +0000</pubDate>
      <link>https://dev.to/anhp9669/inside-the-money-flow-in-centralized-exchanges-mpc-tee-at-work-2bfi</link>
      <guid>https://dev.to/anhp9669/inside-the-money-flow-in-centralized-exchanges-mpc-tee-at-work-2bfi</guid>
      <description>&lt;p&gt;Have you ever wondered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;em&gt;Where do my tokens go when I deposit them to a CEX?&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;em&gt;Why do I always receive tokens from a Binance Hot Wallet instead of the one I deposited to?&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;em&gt;What exactly are hot, warm, and cold wallets?&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s unwrap the secret flow of money inside centralized exchanges. You’ll also learn how technologies like MPC (Multi-Party Computation) and TEE (Trusted Execution Environment) silently power these systems behind the scenes.&lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://research.binance.com/static/pdf/institutional-custody-in-crypto--.pdf?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;Institutional Custody in Crypto - Binance Research&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.fireblocks.com/blog/hot-vs-warm-vs-cold-which-crypto-wallet-is-right-for-me?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;Hot vs. cold vs. warm wallets: Which crypto wallet is right for me?&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.axios.com/2023/01/25/binance-8-wallet-error-commingling?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;Binance's 8 Wallet "error" was there for all to see&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.wired.com/story/hack-binance-cryptocurrency-exchange?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;Hack Brief: Hackers Stole $40 Million from Binance Cryptocurrency Exchange&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What are hot, warm and cold wallets?
&lt;/h2&gt;

&lt;p&gt;Hot, warm, and cold wallets describe how exposed your keys are to the internet. Hot wallets are always online, fast and automated, but riskier. Cold wallets are fully offline, ultra-secure but slow. Warm wallets sit in between: connected, but require human approvals before signing. A serious setup uses all three, hot for withdrawals, warm for ops, cold for long-term reserves.&lt;/p&gt;

&lt;p&gt;In short:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The colder the wallet, the safer the funds.&lt;/li&gt;
&lt;li&gt;  The hotter the wallet, the closer it is to the internet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmjypzb0m5ntembxte6fl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmjypzb0m5ntembxte6fl.png" width="800" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 1 - Wallet layers in a CEX system&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Hot Wallet&lt;/th&gt;
&lt;th&gt;Warm Wallet&lt;/th&gt;
&lt;th&gt;Cold Wallet&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Accessibility&lt;/td&gt;
&lt;td&gt;Fully online&lt;/td&gt;
&lt;td&gt;Online/semi-online&lt;/td&gt;
&lt;td&gt;Fully offline&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Speed&lt;/td&gt;
&lt;td&gt;Real-time&lt;/td&gt;
&lt;td&gt;Delayed&lt;/td&gt;
&lt;td&gt;Manual (hours-days)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Security&lt;/td&gt;
&lt;td&gt;Medium (MPC)&lt;/td&gt;
&lt;td&gt;High (MPC/Multisig)&lt;/td&gt;
&lt;td&gt;Max (air-gapped)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Transaction Volume&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;Very low&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Balance Size&lt;/td&gt;
&lt;td&gt;Small&lt;/td&gt;
&lt;td&gt;Medium-large&lt;/td&gt;
&lt;td&gt;Very large (reserves)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Automation Level&lt;/td&gt;
&lt;td&gt;Full auto&lt;/td&gt;
&lt;td&gt;Semi-auto&lt;/td&gt;
&lt;td&gt;Manual&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MPC Use&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;✅ Yes / Some&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;When it comes to handling billions in customer funds, major centralized exchanges don’t rely on a single wallet type. Instead, they deploy a tiered wallet system: hot, warm, and cold with each serving a distinct role in balancing speed, security, and operational control. Hot wallets power real-time deposits and withdrawals. Warm wallets act as secure liquidity buffers. And cold wallets serve as deep storage vaults, often air-gapped and heavily restricted.&lt;/p&gt;

&lt;p&gt;But hardware separation alone isn’t enough. Today’s top-tier CEXs layer in &lt;strong&gt;Multi-Party Computation (MPC)&lt;/strong&gt; to split key control across distributed nodes, and &lt;strong&gt;Trusted Execution Environments (TEE)&lt;/strong&gt; to guarantee secure signing inside isolated memory. This combination allows exchanges to automate flows like deposit crediting or hot wallet refills while maintaining strong safeguards against internal compromise, external exploits, or key leakage.&lt;/p&gt;

&lt;p&gt;Now let’s walk through how funds actually move through this system from the second a deposit hits the chain to how withdrawals are routed securely.&lt;/p&gt;




&lt;h2&gt;
  
  
  Deposit Flow
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F45y7lqmnuv0fjxubg0e0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F45y7lqmnuv0fjxubg0e0.png" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 2 - Deposit flow in a CEX system&lt;/p&gt;

&lt;p&gt;The process works as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Users deposit tokens onchain to the User Deposit Wallet&lt;/strong&gt;, which is an HD (Hierarchical Deterministic) wallet derived from a single master seed securely stored in CloudHSM. This approach allows the CEX to manage millions of user addresses scalably and efficiently without exposing private keys.
(&lt;code&gt;user1DepositAddress = hdWallet.drivePath("m/44'/60'/0'/0/0""&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Sweep Engine monitors the blockchain&lt;/strong&gt; in real time to detect a deposit transaction to that specific User Deposit Wallet, then initiates a signing request to the Signer to sweep the full balance.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sweep Engine validates against multiple Decision Engines&lt;/strong&gt;, including:&lt;br&gt;&lt;br&gt;
- &lt;strong&gt;Rule Engine&lt;/strong&gt;: Enforces business logic and platform configuration — e.g., token paused status, minimum sweep size, whitelisted destination addresses, and deposit wallet-to-user mapping.&lt;br&gt;&lt;br&gt;
- &lt;strong&gt;Risk Engine&lt;/strong&gt;: Identifies fraud or abuse patterns — e.g., flagged wallets (via Chainalysis/TRM), high-frequency or high-value deposits, interactions with mixers, or connections to known exploiters.&lt;br&gt;&lt;br&gt;
- &lt;strong&gt;Compliance / Sanctions Engine&lt;/strong&gt;: Ensures compliance with global regulations — e.g., blocking OFAC-listed addresses, embargoed jurisdictions, or triggering AML thresholds.&lt;br&gt;&lt;br&gt;
- &lt;strong&gt;Balance Reconciliation Engine&lt;/strong&gt;: Verifies state consistency — e.g., deposit properly recorded in internal DB, current hot wallet balance aligns with expectations, and prevents duplicate sweeps.&lt;br&gt;&lt;br&gt;
- &lt;strong&gt;Fee Estimator / Gas Oracle&lt;/strong&gt;: Optimizes transaction fees — e.g., evaluating current base fee, fee spike protection, checking native token balance for gas sufficiency.&lt;br&gt;&lt;br&gt;
- &lt;strong&gt;Capacity &amp;amp; Health Engine&lt;/strong&gt;: Ensures operational readiness — e.g., confirming the hot wallet is not overloaded, no stuck or pending transactions, and all underlying blockchain nodes are healthy.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Once all rule checks pass&lt;/strong&gt;, the Sweep Engine sends a request to the Signer: “&lt;em&gt;Hey Signer, I have a transaction from wallet &lt;code&gt;0x4eaf...g14d&lt;/code&gt; and it passed all validations. Please help me sign it.&lt;/em&gt;"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Signer runs in a Trusted Execution Environment (TEE)&lt;/strong&gt;, securely loads the private key (via CloudHSM), and performs the signing operation within an isolated, tamper-proof enclave.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The signed transaction is returned to the Sweep Engine&lt;/strong&gt;, which then broadcasts it to the blockchain network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Funds are now swept into the Hot Wallet (MPC-powered)&lt;/strong&gt;. This wallet is connected to critical services but kept isolated via &lt;strong&gt;MPC&lt;/strong&gt; to reduce exposure and avoid single-point key compromise.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;If the Hot Wallet balance exceeds a defined threshold&lt;/strong&gt;, the system automatically triggers a transfer to the Warm Wallet. The Warm Wallet uses &lt;strong&gt;MPC&lt;/strong&gt; as well, but includes human approval gates, typically signers like the CEO, CTO, and CFO.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Once all designated human signers approve the transfer&lt;/strong&gt;, funds are moved to the Cold Wallet (e.g., Ledger hardware wallet), which remains completely offline and air-gapped.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Withdraw flow
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjvfjavpp9pdbqiyquuu7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjvfjavpp9pdbqiyquuu7.png" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figure 3 - Withdraw flow in a CEX system&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;User Request Flow&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; The user kicks off a withdrawal request from the frontend.&lt;/li&gt;
&lt;li&gt; That request hits the CEX Backend, which immediately validates against Decision Engines (risk checks, velocity rules, balance logic, etc.).&lt;/li&gt;
&lt;li&gt; If everything passes, the transaction goes into a TX queue, where it’s grouped with others for gas saving.&lt;/li&gt;
&lt;li&gt; Once ready, the batch is submitted to the Hot Wallet (&lt;strong&gt;MPC&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt; The Hot Wallet signs and sends funds straight to the user’s Destination Wallet.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Hot Wallet Refill Flow&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; Behind the scenes, a balance watcher keeps an eye on hot wallet liquidity.&lt;/li&gt;
&lt;li&gt; If the balance dips too low, the system automatically triggers a refill.&lt;/li&gt;
&lt;li&gt; The Signer Group gets notified.&lt;/li&gt;
&lt;li&gt; They review and sign the refill request.&lt;/li&gt;
&lt;li&gt; Funds flow in from the Warm Wallet (MPC with human approvals) to top up the hot wallet.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Warm Wallet Refill Flow&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt; Meanwhile, a separate process keeps monitoring the Warm Wallet’s balance.&lt;/li&gt;
&lt;li&gt; When it gets low, an automated refill request is raised to the Operator Group.&lt;/li&gt;
&lt;li&gt; This step is highly manual by design. A multi-person operation on a secure workstation approves the refill using hardware wallets.&lt;/li&gt;
&lt;li&gt; Once cleared, the funds move from the Cold Wallet (Ledger) into the Warm Wallet.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Major exchanges rely on a multi-tier wallet setup: hot, warm, and cold to balance speed and security. At the heart of this system, &lt;strong&gt;MPC&lt;/strong&gt; ensures no single party ever holds the full private key, while &lt;strong&gt;TEE&lt;/strong&gt; secures signing operations in isolated hardware. Together, they protect billions in assets against both internal threats and external attacks.&lt;/p&gt;

&lt;p&gt;💡&lt;/p&gt;

&lt;p&gt;&lt;em&gt;*&lt;strong&gt;&lt;em&gt;About Us&lt;/em&gt;&lt;/strong&gt;*&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;At&lt;/strong&gt; &lt;em&gt;*&lt;strong&gt;&lt;em&gt;Fystack&lt;/em&gt;&lt;/strong&gt;*&lt;/em&gt;&lt;strong&gt;, we provide a self-hosted MPC infrastructure designed for teams building secure, scalable Centralized Exchanges (CEXs) and stablecoin infrastructure. Plug it into your existing stack and stay in control, no vendor lock-in, no compromises.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;👉 Contact us&lt;/strong&gt; &lt;strong&gt;at&lt;/strong&gt; &lt;a href="https://fystack.io/?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;&lt;em&gt;*&lt;strong&gt;&lt;em&gt;fystack.io&lt;/em&gt;&lt;/strong&gt;*&lt;/em&gt;&lt;/a&gt; &lt;strong&gt;for self-hosted MPC wallet infrastructure or try&lt;/strong&gt; &lt;a href="https://app.fystack.io/?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;&lt;strong&gt;Fystack&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;for free now!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>blockchain</category>
      <category>mpc</category>
      <category>programming</category>
    </item>
    <item>
      <title>DEK-KEK the industry standard to protect highly sensitive data (Part 1)</title>
      <dc:creator>Anh Phan</dc:creator>
      <pubDate>Wed, 23 Jul 2025 07:46:10 +0000</pubDate>
      <link>https://dev.to/anhp9669/dek-kek-the-industry-standard-to-protect-highly-sensitive-data-part-1-4910</link>
      <guid>https://dev.to/anhp9669/dek-kek-the-industry-standard-to-protect-highly-sensitive-data-part-1-4910</guid>
      <description>&lt;p&gt;&lt;em&gt;(Part 1 - Foundational concepts)&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Read the original post over here &lt;a href="https://fystack.io/blog/dek-kek-the-industry-standard-to-protect-highly-sensitive-data-part-1" rel="noopener noreferrer"&gt;&lt;strong&gt;Fystack Blog&lt;/strong&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;DEK-KEK is a hybrid encryption approach designed to balance security, performance, and operational simplicity. It’s widely adopted by institutional enterprises, think banks, insurance companies, and crypto exchanges where centralized servers must store extremely sensitive data such as PII (Personally Identifiable Information), crypto private keys, or MPC keyshares.&lt;/p&gt;

&lt;p&gt;References and industry examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://learn.microsoft.com/en-us/azure/security/fundamentals/encryption-atrest?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;&lt;strong&gt;Microsoft Azure – Encryption at Rest&lt;/strong&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://cloud.google.com/kms/docs/envelope-encryption?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;&lt;strong&gt;Google Cloud KMS – Envelope Encryption&lt;/strong&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://en.wikipedia.org/wiki/Hybrid_cryptosystem?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;&lt;strong&gt;Wikipedia – Hybrid Cryptosystem (Envelope Encryption)&lt;/strong&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://zerotohero.dev/inbox/dek-kek/?utm_source=chatgpt.com" rel="noopener noreferrer"&gt;&lt;strong&gt;ZeroToHero – Understanding DEK and KEK in Encryption&lt;/strong&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's get started by some foundational concepts, industry standards for data protection and how Fystack makes technical decisions and apply them on Part 2 (coming soon)&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Encryption Models in Play&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Symmetric Encryption&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A single private key is used for both encryption and decryption.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Pros:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  Simple and fast.&lt;/li&gt;
&lt;li&gt;  Low computational cost.&lt;/li&gt;
&lt;li&gt;  Standardized algorithms (e.g., AES).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Cons:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  Key sharing is risky.&lt;/li&gt;
&lt;li&gt;  Key compromise breaks security.&lt;/li&gt;
&lt;li&gt;  No non-repudiation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Use Cases:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Data-at-rest encryption&lt;/strong&gt; (e.g., database fields, file storage, backups).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Data-in-transit encryption&lt;/strong&gt; when combined with key exchange protocols (e.g., TLS session keys).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Disk encryption&lt;/strong&gt; (BitLocker, LUKS) or &lt;strong&gt;cloud storage encryption&lt;/strong&gt; (AWS S3 SSE).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Bulk data transfer&lt;/strong&gt;, due to its speed and efficiency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbqnyez2227e0rl94hs8q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbqnyez2227e0rl94hs8q.png" width="800" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1.1 - Symmetric encryption/decryption model&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;AES-GCM-256 is chosen as the core algorithm for symmetric encryption/decryption. It ensures both confidentiality (data is unreadable without the key) and integrity (detects any tampering with the ciphertext).&lt;/p&gt;

&lt;p&gt;💡&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Why AES-GCM-256?&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;AES (Advanced Encryption Standard) is a proven symmetric encryption algorithm trusted worldwide. The GCM (Galois/Counter Mode) variant adds authenticated encryption, meaning it not only encrypts data but also verifies its integrity. AES-GCM-256 is favored because it is:&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;- Fast and hardware-accelerated on most modern CPUs.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;- Widely audited and trusted, meeting banking and government security standards.&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;- Resistant to common cryptographic attacks, making it the default choice for enterprise-grade encryption.&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;AES-GCM-256 Encryption Process&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Input:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Plaintext (&lt;code&gt;[]byte&lt;/code&gt;)&lt;/strong&gt; – Raw data to be encrypted (e.g., JSON, string, binary).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;DEK (&lt;code&gt;[]byte&lt;/code&gt;)&lt;/strong&gt; – 32-byte Data Encryption Key used by AES-256-GCM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Nonce (&lt;code&gt;string&lt;/code&gt;)&lt;/strong&gt; – Base64-encoded 12-byte random nonce required for decryption.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Ciphertext (&lt;code&gt;string&lt;/code&gt;)&lt;/strong&gt; – Base64-encoded encrypted data, which includes the GCM authentication tag.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pytvsc8ecfzl0c99m42.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6pytvsc8ecfzl0c99m42.png" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1.2 - AES-GCM-256 encryption architectural diagram&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;AES-GCM-256 Decryption Process&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Input:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Ciphertext (&lt;code&gt;string&lt;/code&gt;)&lt;/strong&gt; – Base64-encoded ciphertext as stored in the database.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Nonce (&lt;code&gt;string&lt;/code&gt;)&lt;/strong&gt; – Base64-encoded nonce generated during encryption.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;DEK (&lt;code&gt;[]byte&lt;/code&gt;)&lt;/strong&gt; – 32-byte Data Encryption Key used for decryption.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Plaintext (&lt;code&gt;[]byte&lt;/code&gt;)&lt;/strong&gt; – The original decrypted raw data (convert to string with &lt;code&gt;string(plaintext)&lt;/code&gt; if needed).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhc5l5eihw59w884zfza9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhc5l5eihw59w884zfza9.png" width="800" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1.3 - AES-GCM-256 decryption architectural diagram&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;2. Asymmetric Encryption&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Uses a pair of keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A &lt;strong&gt;public key&lt;/strong&gt; for encryption (or signature verification).&lt;/li&gt;
&lt;li&gt;  A &lt;strong&gt;private key&lt;/strong&gt; for decryption (or signing).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fthyz0ll17khksqj27ej9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fthyz0ll17khksqj27ej9.png" width="800" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1.4 Asymmetric encryption/decryption model&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Pros:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  No shared private keys.&lt;/li&gt;
&lt;li&gt;  Supports digital signatures.&lt;/li&gt;
&lt;li&gt;  Good for secure key exchange.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Cons:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  Slower and resource-heavy.&lt;/li&gt;
&lt;li&gt;  Larger key sizes.&lt;/li&gt;
&lt;li&gt;  Complex key management.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Use cases:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Key exchange protocols&lt;/strong&gt; (e.g., TLS handshake to establish symmetric session keys).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Digital signatures&lt;/strong&gt; and &lt;strong&gt;certificate-based authentication&lt;/strong&gt; (e.g., SSL certificates, JWT signing).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Cryptocurrency wallets&lt;/strong&gt; (e.g., signing transactions with private keys).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Intuitive approach
&lt;/h2&gt;

&lt;p&gt;Let's start from the most common table in every system &lt;code&gt;User&lt;/code&gt;, the primary key is &lt;code&gt;user_id&lt;/code&gt; and a sensitive &lt;code&gt;otp_secret&lt;/code&gt;, others are omitted for the sake of simplicity.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhba656bjyqrmnahd7b4w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhba656bjyqrmnahd7b4w.png" width="800" height="407"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1.5 - Intuitive approach to protect data at-rest&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Imagine a disaster strikes when no engineers are around — say, during the holidays. The database gets compromised, and the attacker gains access to all users' OTP secrets in plaintext, effectively bypassing 2FA protection to launch further attacks.&lt;/p&gt;

&lt;p&gt;A robust protection mechanism for data at rest is essential. Even in the worst-case scenario, the attacker should only see encrypted data, rendering it useless for further exploitation. To achieve this, an encryption key is introduced as the core defense.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmf18fojjcj4vx9pqiylx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmf18fojjcj4vx9pqiylx.png" width="800" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1.6 - enhanced approach to protect data at-rest&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The encryption key can be either a symmetric or asymmetric key and is often managed by cloud provider serverless services (AWS KMS, GCP KMS, Azure Key Vault). When a user query is made, the backend service will load encrypted fields from database, call to Key Management Service (KMS) to decrypt it then return result to client. However this approach still comes with some disadvantages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The encryption key becomes the single point of compromise.&lt;/li&gt;
&lt;li&gt;  Huge operational efforts on rotating encryption key (including re-encrypt every row in database).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is where DEK-KEK model was born and becomes the industry standard.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;What are DEK and KEK?&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;DEK (Data Encryption Key):&lt;/strong&gt; A symmetric key used directly to encrypt and decrypt data.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;KEK (Key Encryption Key):&lt;/strong&gt; A key (often asymmetric) used to encrypt DEKs, protecting them from being compromised while at rest.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By layering encryption like this, KEKs safeguard DEKs, while DEKs efficiently handle the encryption of large volumes of data.&lt;/p&gt;

&lt;p&gt;💡&lt;/p&gt;

&lt;p&gt;*DEK vs. KEK Lifecycle  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DEK: stored at-rest with encryption, loaded into memory (plaintext) when the backend service boots up and is securely wiped from memory when the server shuts down.
&lt;/li&gt;
&lt;li&gt;KEK: managed by cloud providers, with backend access restricted by Role-Based Access Control (RBAC)*&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpm91tvq4j22bo87equ1i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpm91tvq4j22bo87equ1i.png" width="800" height="497"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Figure 1.7 - DEK-KEK practical implementation&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The diagram illustrates how the DEK-KEK encryption model works in a real-world system. At the top of the hierarchy is the Key Encryption Key (KEK), usually stored and managed by a secure service such as AWS KMS, Azure Key Vault, or GCP Cloud KMS. The KEK never encrypts user data directly. Instead, it’s responsible for protecting another key — the Data Encryption Key (DEK) — which is used for actual data encryption and decryption.&lt;/p&gt;

&lt;p&gt;The process works as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; A DEK (symmetric key) is generated and then immediately encrypted with the KEK. The encrypted version of the DEK is stored in the database, represented by the &lt;code&gt;encrypted_dek&lt;/code&gt; column (base64-encoded).&lt;/li&gt;
&lt;li&gt; When the application needs to perform encryption or decryption, it retrieves the encrypted DEK, has it decrypted by the KEK, and loads the plain DEK into memory.&lt;/li&gt;
&lt;li&gt; The DEK, which is much faster for bulk operations, handles the encryption and decryption of sensitive data such as the &lt;code&gt;otp_secret&lt;/code&gt; field.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This model provides a strong balance between security and performance:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The KEK remains protected in a hardened key management service or hardware security module. It follows the strict principle that the key's plaintext version never leaves the service, ensuring that no user, system or process can directly access or view it.&lt;/li&gt;
&lt;li&gt;  The DEK, while briefly present in memory, is never stored in plaintext at rest. The memory can be further protected at both the software and hardware layers, for example, using AWS Nitro Enclaves as the Trusted Execution Environment (TEE).&lt;/li&gt;
&lt;li&gt;  Symmetric encryption ensures fast operations without frequent, costly calls to KMS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Moreover, this model significantly reduces operational effort required when it is time to rotate the KEK. The entire database remains unchanged. The DEK is re-encrypted in memory by the new KEK then stored back to the database. Simple, secure and efficient!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- To be continued -&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In Part 2, we’ll share how &lt;a href="https://fystack.io/?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;Fystack&lt;/a&gt; adopted this model to strengthen our MPC wallet infrastructure, the challenges we faced, and the key technical decisions behind it. Stay tuned!&lt;/p&gt;

&lt;p&gt;💡&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;At Fystack, we provide self-hosted MPC wallet infrastructure designed for teams that value security, control, and flexibility.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;👉 Contact us&lt;/strong&gt; &lt;strong&gt;at&lt;/strong&gt; &lt;a href="https://fystack.io/?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;&lt;em&gt;*&lt;strong&gt;&lt;em&gt;fystack.io&lt;/em&gt;&lt;/strong&gt;*&lt;/em&gt;&lt;/a&gt; &lt;strong&gt;for self-hosted MPC wallet infrastructure or try&lt;/strong&gt; &lt;a href="https://app.fystack.io/?ref=ghost.fystack.io" rel="noopener noreferrer"&gt;&lt;strong&gt;Fystack&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;for free now!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>blockchain</category>
      <category>mpc</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
