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.
- 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
The app uses the encrypt package to implement AES encryption. Here's how the CryptService works:
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
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;
}- The key is normalized to 32 bytes
- A fixed Initialization Vector (IV) is used
- An AES encrypter is created in CBC mode
- The text is encrypted and returned as a base64 string
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';
}
}- Uses the same key normalization and IV
- Attempts to decrypt the base64-encoded text
- Returns an error message if decryption fails
String plaintext = "Hello, World!";
String key = "MySecretKey123";
String encrypted = CryptService.encryptText(plaintext, key);
// Output: "YW5kb21FbmNyeXB0ZWRTdHJpbmc=" (example output)String encryptedText = "YW5kb21FbmNyeXB0ZWRTdHJpbmc=";
String key = "MySecretKey123";
String decrypted = CryptService.decryptText(encryptedText, key);
// Output: "Hello, World!"- 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
- Clone the repository:
git clone https://github.com/d3mastermind/LockIn.git- Navigate to the project directory:
cd LockIn- Install dependencies:
flutter pub get- Run the app:
flutter runContributions are welcome! Please feel free to submit a Pull Request.