Flutter Android login vault: local DB (id+base64 content), email/Google auth, dashboard search/edit/swipe-delete, dark/system theme, minSdk 29
This commit is contained in:
29
lib/encryptor.dart
Normal file
29
lib/encryptor.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'dart:convert';
|
||||
import 'package:login_vault_app/constants.dart';
|
||||
|
||||
/// XOR cipher keyed by [AppConstants.encryptionKey], then base64-encoded.
|
||||
///
|
||||
/// Operates on raw bytes so any Unicode content round-trips correctly.
|
||||
class Encryptor {
|
||||
static List<int> _xorBytes(List<int> input, List<int> key) {
|
||||
final out = List<int>.filled(input.length, 0);
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
out[i] = input[i] ^ key[i % key.length];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// Encrypt [plain] -> base64 string using the constant key.
|
||||
static String encrypt(String plain) {
|
||||
final keyBytes = utf8.encode(AppConstants.encryptionKey);
|
||||
final xored = _xorBytes(utf8.encode(plain), keyBytes);
|
||||
return base64.encode(xored);
|
||||
}
|
||||
|
||||
/// Decrypt a base64 [cipher] produced by [encrypt].
|
||||
static String decrypt(String cipher) {
|
||||
final keyBytes = utf8.encode(AppConstants.encryptionKey);
|
||||
final xored = _xorBytes(base64.decode(cipher), keyBytes);
|
||||
return utf8.decode(xored);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user