reKey method

bool reKey(
  1. String? cryptKey
)

Change encryption key for the MMKV instance.

  • The cryptKey is 16 bytes limited.
  • You can transfer a plain-text MMKV into encrypted by setting an non-null, non-empty cryptKey.
  • Or vice versa by passing cryptKey with null. See also checkReSetCryptKey().

Implementation

bool reKey(String? cryptKey) {
  if (cryptKey != null && cryptKey.isNotEmpty) {
    final bytes = MMBuffer.fromList(const Utf8Encoder().convert(cryptKey))!;
    final ret = _reKey(_handle, bytes.pointer!, bytes.length);
    bytes.destroy();
    return _int2Bool(ret);
  } else {
    final ret = _reKey(_handle, nullptr, 0);
    return _int2Bool(ret);
  }
}