authenticate3DES method
Performs 3DES authentication with a provided key.
This advanced authentication method uses Triple DES encryption to securely authenticate with an RFID tag. It requires a properly formatted key and involves multiple steps of encryption and decryption to achieve authentication.
Parameters
key: A list of integers representing the 3DES key used for authentication. The key length and format must comply with 3DES standards.
Throws
Exceptionfor invalid responses during the authentication process, indicating potential issues with the key, communication, or tag's response.
Example
await reader.authenticate3DES(key: [/* 24-byte 3DES key */]);
Note: This method is intended for use with RFID systems that support 3DES authentication. Ensure that the key and system configurations are secure and conform to best practices.
Implementation
@override
Future<void> authenticate3DES({required List<int> key}) async {
  final a = getRandomBytes(length: 8);
  final ekBResponse = await transmitDirect(
    data: [0xD4, 0x42, 0x1A, 0x00],
  );
  if (ekBResponse.length != 12) {
    throw Exception('Invalid response');
  }
  final ekB = ekBResponse.sublist(4);
  final b = DES3(
    key: key,
    mode: DESMode.CBC,
    iv: [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00],
  ).decrypt(ekB);
  final bDash = rotateListData(b, 1);
  final ekABDash = DES3(
    key: key,
    mode: DESMode.CBC,
    iv: ekB,
  ).encrypt(a + bDash).sublist(0, 16);
  final ekADashResponse = await transmitDirect(
    data: [0xD4, 0x42, 0xAF] + ekABDash,
  );
  if (ekADashResponse.length != 12) {
    throw Exception('Invalid response');
  }
  final ekADash = ekADashResponse.sublist(4, 12);
  final aDash = DES3(
    key: key,
    mode: DESMode.CBC,
    iv: ekABDash.sublist(8, 16),
  ).decrypt(ekADash);
  final aDashComp = rotateListData(a, 1);
  for (var i = 0; i < 8; i++) {
    if (aDashComp[i] != aDash[i]) {
      throw Exception('Invalid response');
    }
  }
}