matchSymmetricKeys static method
Verifies that symmetric keys (encrypt/decrypt) are a matching pair.
Tests if the encryption key can encrypt the PROMISE data, and the decryption key can successfully decrypt it back to the original data.
encKey is the encryption key to test.
decKey is the decryption key to test.
Returns true if keys are a valid matching pair, false otherwise.
Implementation
static bool matchSymmetricKeys(EncryptKey encKey, DecryptKey decKey) {
// check by encryption
final params = <String, dynamic>{}.asMutableMapping();
Uint8List ciphertext = encKey.encrypt(PROMISE, params);
Uint8List? plaintext = decKey.decrypt(ciphertext, params);
return plaintext != null && Arrays.equals(plaintext, PROMISE);
}