public static void ValidateTag(byte[] data) { byte[][] pages = TagUtil.SplitPages(data); if (pages[0][0] != (byte)0x04) { throw new Exception("Invalid tag file. Tag must start with a 0x04."); } if (pages[2][2] != (byte)0x0F || pages[2][3] != (byte)0xE0) { throw new Exception("Invalid tag file. lock signature mismatch."); } if (pages[3][0] != (byte)0xF1 || pages[3][1] != (byte)0x10 || pages[3][2] != (byte)0xFF || pages[3][3] != (byte)0xEE) { throw new Exception("Invalid tag file. CC signature mismatch."); } if (pages[0x82][0] != (byte)0x01 || pages[0x82][1] != (byte)0x0 || pages[0x82][2] != (byte)0x0F) { throw new Exception("Invalid tag file. dynamic lock signature mismatch."); } if (pages[0x83][0] != (byte)0x0 || pages[0x83][1] != (byte)0x0 || pages[0x83][2] != (byte)0x0 || pages[0x83][3] != (byte)0x04) { throw new Exception("Invalid tag file. CFG0 signature mismatch."); } if (pages[0x84][0] != (byte)0x5F || pages[0x84][1] != (byte)0x0 || pages[0x84][2] != (byte)0x0 || pages[0x84][3] != (byte)0x00) { throw new Exception("Invalid tag file. CFG1 signature mismatch."); } }
public static bool WriteToTagAuto(MifareUltralight mifare, byte[] tagData, KeyManager keyManager) { tagData = AdjustTag(keyManager, tagData, mifare); if (!Validate(mifare, tagData) || !ValidateBlankTag(mifare)) { return(false); } try { byte[][] pages = TagUtil.SplitPages(tagData); WritePages(mifare, 3, 129, pages); Console.WriteLine("Wrote main data", Color.Green); } catch (Exception e) { Console.WriteLine("Error while writing main data (stage 1)", Color.Red); return(false); } try { WritePassword(mifare); Console.WriteLine("Wrote password", Color.Green); } catch (Exception e) { Console.WriteLine("Error while setting password (stage 2)", Color.Red); return(false); } try { WriteLockInfo(mifare); Console.WriteLine("Wrote lock info", Color.Green); } catch (Exception e) { Console.WriteLine("Error while setting lock info (stage 3)", Color.Red); return(false); } return(true); }