verifyEncKey method

Future<bool> verifyEncKey(
  1. String plaintextEncKey
)

Encryption key verification with the hash value stored in the server

Implementation

Future<bool> verifyEncKey(String plaintextEncKey) async {
  String sha224Result = sha224
      .convert(utf8.encode(plaintextEncKey))
      .toString()
      .substring(0, 32);
  String sha256Result = sha256
      .convert(utf8.encode(plaintextEncKey))
      .toString()
      .substring(0, 32);

  var keyInfo = await fetchFile(encKeyFileLoc);
  EncProfile keyFile = EncProfile(keyInfo.toString());
  String encKeyHash = keyFile.getEncKeyHash();

  if (encKeyHash != sha224Result) {
    /// If the stored hash value is the same
    return false;
  } else {
    /// If not
    setEncKeyStorage(sha256Result);
    return true;
  }
}