private static bool IsTagValid(NFCSharp.NFCTag tag) { if (tag == null) { return(false); } try { var ndef = tag.NDEFRead(); if (ndef.Count != 5) { return(false); } for (int i = 0; i < 5; i++) { if (ndef[i].Payload == null || (_encryptData && EncDec.Unprotect(ndef[i].Payload) == null)) { return(false); } } return(true); } catch (Exception ex) { Logger.Log(" IsTagValid: NDEFRead failed:" + ex.HResult + " - " + ex.ToString()); // -2146233088 is a parse error which usually means the tag isn't formatted if (ex.HResult != -2146233088) { System.Diagnostics.Debug.WriteLine("NDEFRead failed:" + ex.ToString()); return(false); } } return(false); }
private bool LoadTagData() { if (_tag == null || !IsTagValid()) { return(false); } Logger.Log(" LoadTagData loading"); var ndef = _tag.NDEFRead(); var data0 = ndef[0].Payload; var data1 = _encryptData ? EncDec.Unprotect(ndef[1].Payload) : ndef[1].Payload; var data2 = _encryptData ? EncDec.Unprotect(ndef[2].Payload) : ndef[2].Payload; var data3 = _encryptData ? EncDec.Unprotect(ndef[3].Payload) : ndef[3].Payload; var data4 = ndef[4].Payload; DeviceName = Encoding.ASCII.GetString(data0).TrimEnd(Convert.ToChar(0x0)); ipAddress = Encoding.ASCII.GetString(data1).TrimEnd(Convert.ToChar(0x0)); username = Encoding.ASCII.GetString(data2).TrimEnd(Convert.ToChar(0x0)); password = Encoding.ASCII.GetString(data3).TrimEnd(Convert.ToChar(0x0)); var temp = Encoding.ASCII.GetString(data4).TrimEnd(Convert.ToChar(0x0)); return(true); }