<?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: RAYMOND ADERINTO</title>
    <description>The latest articles on DEV Community by RAYMOND ADERINTO (@raymond_aderinto_62eff394).</description>
    <link>https://dev.to/raymond_aderinto_62eff394</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%2F3422545%2F49f92cc0-501e-4982-aa40-1909c410a752.png</url>
      <title>DEV Community: RAYMOND ADERINTO</title>
      <link>https://dev.to/raymond_aderinto_62eff394</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raymond_aderinto_62eff394"/>
    <language>en</language>
    <item>
      <title>Flutter Data Security: Building an AES Encryption Utility from Scratch</title>
      <dc:creator>RAYMOND ADERINTO</dc:creator>
      <pubDate>Fri, 08 Aug 2025 19:45:38 +0000</pubDate>
      <link>https://dev.to/raymond_aderinto_62eff394/flutter-data-security-building-an-aes-encryption-utility-from-scratch-1c2g</link>
      <guid>https://dev.to/raymond_aderinto_62eff394/flutter-data-security-building-an-aes-encryption-utility-from-scratch-1c2g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have always known security was important, but one project really hammered it home for me.&lt;br&gt;
While working on a fintech app, I realised some sensitive user data wasn’t as protected as it should be. Nothing bad had happened yet — but I could see the risk, and honestly, it made my stomach drop.&lt;/p&gt;

&lt;p&gt;When you work on sensitive apps, you’re responsible for your code. If there’s a data breach and you left something amiss — or forgot to lock the system down — you can be prosecuted. That thought keeps me up at night, knowing I could go to the office one morning and not come back home. So I became a little bit obsessed with securing my app.&lt;/p&gt;

&lt;p&gt;I rolled up my sleeves and built a proper AES encryption system to lock everything down — from API tokens to personal details. It gave me peace of mind, and I figured… why keep this to myself? If sharing my approach helps even one other developer avoid that “oh no” moment, it’s worth it.&lt;/p&gt;

&lt;p&gt;Data security is no longer optional — whether you’re building a fintech app, a messaging platform, or an IoT solution, protecting sensitive information is crucial. In Flutter, you can implement strong encryption with packages like encrypt to secure data both at rest and in transit.&lt;/p&gt;

&lt;p&gt;In this article, we’ll explore:&lt;br&gt;
    • What encryption is and why it matters.&lt;br&gt;
    • How AES encryption works in Flutter.&lt;br&gt;
    • A real-world example with a reusable encryption utility class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Encryption Matters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Encryption ensures that even if your data is intercepted or accessed by unauthorized parties, it remains unreadable without the correct key.&lt;br&gt;
For example:&lt;br&gt;
    • User passwords&lt;br&gt;
    • Payment details&lt;br&gt;
    • API tokens&lt;br&gt;
    • Sensitive configuration data&lt;/p&gt;

&lt;p&gt;Without encryption, any breach could expose raw, readable information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AES: The Encryption Standard&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Advanced Encryption Standard (AES) is a symmetric encryption algorithm, meaning the same key is used for encryption and decryption.&lt;br&gt;
Key points about AES:&lt;br&gt;
    • Secure and widely adopted.&lt;br&gt;
    • Supports key sizes of 128, 192, or 256 bits.&lt;br&gt;
    • Often paired with modes like CBC (Cipher Block Chaining) and padding schemes like PKCS7 for compatibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting Up Flutter for Encryption&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install the encrypt package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter pub add encrypt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Building a Secure Storage Utility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is a complete SecureStorage class that demonstrates AES encryption in Flutter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:encrypt/encrypt.dart';
import 'dart:convert';
import 'dart:typed_data';

class SecureStorage {
  static final String _keyString = "your api key "; // 32 bytes
  static Key get _key =&amp;gt; Key.fromUtf8(_keyString);

  static String encryptData(String plainText) {
    final iv = IV.fromSecureRandom(16); // Secure, random IV
    final encrypter = Encrypter(AES(_key, mode: AESMode.cbc, padding: "PKCS7"));
    final encrypted = encrypter.encrypt(plainText, iv: iv);

    // Combine IV + Encrypted Data
    final combined = iv.bytes + encrypted.bytes;
    return base64.encode(combined);
  }

  static String decryptData(String encryptedText) {
    try {
      final bytes = base64.decode(encryptedText);

      if (bytes.length &amp;lt; 32) {
        return "Decryption Failed: Not enough data";
      }

      final iv = IV(Uint8List.fromList(bytes.sublist(0, 16)));
      final encryptedData = Encrypted(Uint8List.fromList(bytes.sublist(16)));

      final encrypter = Encrypter(AES(_key, mode: AESMode.cbc, padding: "PKCS7"));
      return encrypter.decrypt(encryptedData, iv: iv);
    } catch (e) {
      return "Decryption Failed: $e";
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;How It Works&lt;/strong&gt;&lt;br&gt;
    1.  The Key&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;static final String _keyString = "your Api Key";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a 32-byte (256-bit) AES key. In production, store it securely (e.g., in in Firebase Remote Config or azure Key Vault).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2.  **Encryption Process**
• Generate a secure random IV (16 bytes for AES).
• Encrypt the data with AES-CBC and PKCS7 padding.
• Combine the IV and the encrypted data into one byte array.
• Base64 encode for safe storage or transmission.


3.  **Decryption Process**
• Base64 decode to get raw bytes.
• Extract the first 16 bytes as the IV.
• Use the remaining bytes as the encrypted payload.
• Decrypt with the same AES key.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Example Usage&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void main() {
  String secret = "Sensitive user data";

  String encrypted = SecureStorage.encryptData(secret);
  print("Encrypted: $encrypted");

  String decrypted = SecureStorage.decryptData(encrypted);
  print("Decrypted: $decrypted");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Encrypted: kfL0L9x0M... (base64 string)
Decrypted: Sensitive user data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Security Considerations&lt;/strong&gt;&lt;br&gt;
    • Key Management: Never hardcode keys in production — use secure storage, environment configs, or key management services.&lt;br&gt;
    • IV Randomness: Always use a new IV for each encryption to ensure security.&lt;br&gt;
    • Obfuscation: Use Flutter’s obfuscation and minification to make reverse-engineering harder.&lt;br&gt;
    • Integrity Checks: Consider adding HMAC to detect tampering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By implementing AES encryption in Flutter with a well-structured utility like SecureStorage, you ensure sensitive data is protected against unauthorised access. With proper key management and secure coding practices, you can significantly improve your app’s security posture.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
