cipherFromKey function

HiveAesCipher? cipherFromKey({
  1. String? key,
})

Generates the cipher directly from a key (password)

Implementation

HiveAesCipher? cipherFromKey({String? key}) {
  if (key == null) {
    return null;
  } else {
    List<int> encoded = utf8.encode(key);
    if (encoded.length == 32) {
      return HiveAesCipher(encoded);
    } else if (encoded.length > 32) {
      return HiveAesCipher(encoded.sublist(0, 32));
    } else {
      encoded =
          encoded + utf8.encode(nonRandomSalt).sublist(0, 32 - encoded.length);
      return HiveAesCipher(encoded);
    }
  }
}