Skip to content

d3mastermind/LockIn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lock In - AES Encryption App

Lock In is a Flutter application that provides a simple interface for encrypting and decrypting text using AES (Advanced Encryption Standard) encryption in CBC (Cipher Block Chaining) mode.

Flutter License

Quick Start

Features

  • Text encryption using AES-256 in CBC mode
  • Text decryption with error handling
  • User-friendly interface with light/dark mode
  • Copy functionality for encrypted/decrypted text
  • Input validation and error handling

Encryption Implementation

The app uses the encrypt package to implement AES encryption. Here's how the CryptService works:

Key Handling

static String _normalizeKey(String key) {
    if (key.length >= 32) return key.substring(0, 32);
    return key.padRight(32, ' ');
}
  • Keys are normalized to exactly 32 bytes (256 bits)
  • If the key is longer than 32 bytes, it's truncated
  • If shorter, it's padded with spaces

Encryption Process

static String encryptText(String text, String key) {
    final keyBytes = encrypt.Key.fromUtf8(_normalizeKey(key));
    final iv = encrypt.IV.fromUtf8('1234567890123456');
    final encrypter = encrypt.Encrypter(
        encrypt.AES(keyBytes, mode: encrypt.AESMode.cbc)
    );

    final encrypted = encrypter.encrypt(text, iv: iv);
    return encrypted.base64;
}
  1. The key is normalized to 32 bytes
  2. A fixed Initialization Vector (IV) is used
  3. An AES encrypter is created in CBC mode
  4. The text is encrypted and returned as a base64 string

Decryption Process

static String decryptText(String encryptedText, String key) {
    final keyBytes = encrypt.Key.fromUtf8(_normalizeKey(key));
    final iv = encrypt.IV.fromUtf8('1234567890123456');
    final encrypter = encrypt.Encrypter(
        encrypt.AES(keyBytes, mode: encrypt.AESMode.cbc)
    );

    try {
        return encrypter.decrypt64(encryptedText, iv: iv);
    } catch (e) {
        return 'Invalid Key or Encrypted Text';
    }
}
  1. Uses the same key normalization and IV
  2. Attempts to decrypt the base64-encoded text
  3. Returns an error message if decryption fails

Example Usage

Encryption Example

String plaintext = "Hello, World!";
String key = "MySecretKey123";
String encrypted = CryptService.encryptText(plaintext, key);
// Output: "YW5kb21FbmNyeXB0ZWRTdHJpbmc=" (example output)

Decryption Example

String encryptedText = "YW5kb21FbmNyeXB0ZWRTdHJpbmc=";
String key = "MySecretKey123";
String decrypted = CryptService.decryptText(encryptedText, key);
// Output: "Hello, World!"

Security Considerations

  • The app uses a fixed IV for simplicity. In a production environment, you should use a random IV for each encryption
  • The key padding mechanism is basic. Consider using a more secure key derivation function for production use

Installation

  1. Clone the repository:
git clone https://github.com/d3mastermind/LockIn.git
  1. Navigate to the project directory:
cd LockIn
  1. Install dependencies:
flutter pub get
  1. Run the app:
flutter run

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published