init method

void init()

Initializes the CryptoModule by generating and storing a new encryption key and initialization vector (IV) in SimpleSharedPref. It only runs once and is safe to be called on app startup.

Implementation

void init() {
  try {
    final key = Key.fromSecureRandom(32);
    final iv = IV.fromSecureRandom(16);
    if (!SimpleSharedPref().containsKey(_obfuscatedKey)) {
      SimpleSharedPref().preferences?.setString(_obfuscatedKey, key.base64);
      SimpleSharedPref().preferences?.setString(_obfuscatedIV, iv.base64);
    }
  } catch (e) {
    print('Initialization error: $e');
  }
}