decrypt static method

String? decrypt(
  1. String ciphertext, [
  2. String decrypter(
    1. String ciphertext
    )?
])

Decrypt the locally stored data.

ciphertext is the data to decrypt.

decrypter is an optional function to decrypt the data with. This will be used in addition to the default decryption. This will be performed after the default decryption.

Returns null if the ciphertext data is invalid or corrupt.

Implementation

static String? decrypt(String ciphertext,
    [String Function(String ciphertext)? decrypter]) {
  try {
    // First, unscramble the data string.
    String unscrambledData = _scramble(ciphertext);

    // Then, convert that data string into bytes and decode the string at the
    // same time.
    List<int> dataBytes = base64.decode(unscrambledData);

    // Remove the salt from the data.
    String unsalted = _removeSalt(utf8.decode(dataBytes));

    // Then, unscramble the data string.
    unscrambledData = _scramble(unsalted);

    // Finally, convert the data string into bytes and decode the string at
    // the same time.
    dataBytes = base64.decode(unscrambledData);

    // Return the decoded data.
    String semiPlaintext = utf8.decode(dataBytes);

    // Decrypt the data with addition decrypter if provided.
    if (decrypter != null) {
      return decrypter(semiPlaintext);
    } else {
      return semiPlaintext;
    }
  } catch (e) {
    return null;
  }
}