private static async Task <int> SetData(byte[] data, int sector, int blockInSector, byte[] keyA, byte[] keyB) { if (data == null) { WriteToLog("!!!! SetData ERROR !!! data null"); throw new Exception("!!!! SetData ERROR !!! data null"); } try { if (keyA != null) { _card.AddOrUpdateSectorKeySet(new SectorKeySet { KeyType = KeyType.KeyA, Sector = sector, Key = keyA }); } if (keyB != null) { _card.AddOrUpdateSectorKeySet(new SectorKeySet { KeyType = KeyType.KeyB, Sector = sector, Key = keyB }); } var sec = _card.GetSector(sector); if (blockInSector == sec.NumDataBlocks - 1) { var access = AccessBits.GetAccessConditions(data); sec.Access.DataAreas[0] = access.DataAreas[0]; sec.Access.DataAreas[1] = access.DataAreas[1]; sec.Access.DataAreas[2] = access.DataAreas[2]; sec.Access.Trailer = access.Trailer; byte[] keyAData = new byte[6]; byte[] keyBData = new byte[6]; Array.Copy(data, 0, keyAData, 0, 6); Array.Copy(data, 10, keyBData, 0, 6); sec.KeyA = keyAData.ByteArrayToString(); sec.KeyB = keyBData.ByteArrayToString(); } else { await sec.SetData(data, blockInSector); } return((int)ErrorCodes.E_SUCCESS); } catch (Exception e) { WriteToLog($"SetData ERROR !!! {e}"); return((int)ErrorCodes.E_GENERIC); } }
internal override void CopyFrom(byte[] data) { base.CopyFrom(data); AccessConditions = AccessBits.GetAccessConditions(data); }