Exemple #1
0
        /// <summary>
        /// Authenticate with key1
        /// </summary>
        private void btnAuthKeyOne_Click(object sender, RoutedEventArgs e)
        {
            Gen2.NXP.AES.Tam2Authentication tam2Auth;
            Gen2.NXP.AES.Tam1Authentication tam1Auth;
            ushort[] Key1, Ichallenge, returnedIchallenge;
            byte[]   Response, Challenge;
            lblDataValue.Content       = "";
            lblTam2DataValue.Content   = "";
            lblChallenge1Value.Content = "";
            switch (cbxReadDataBank.Text)
            {
            case "TID":
                MemoryProfile = Gen2.NXP.AES.Profile.TID;
                break;

            case "User":
                MemoryProfile = Gen2.NXP.AES.Profile.USER;
                break;

            case "EPC":
                MemoryProfile = Gen2.NXP.AES.Profile.EPC;
                break;
            }

            if (txtbxVerifyKeyOne.Text.Length == 32)
            {
                byte[] KeytoWrite = ByteFormat.FromHex(txtbxVerifyKeyOne.Text);
                Key1 = new ushort[KeytoWrite.Length / 2];
                Key1 = ByteConv.ToU16s(KeytoWrite);
            }
            else
            {
                MessageBox.Show("Please input valid Key1", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            byte[] randmNumber = ByteFormat.FromHex(lblRandomChallengeValue.Content.ToString().Replace(" ", ""));
            Ichallenge = new ushort[randmNumber.Length / 2];
            Ichallenge = ByteConv.ToU16s(randmNumber);

            try
            {
                if ((bool)chkReadData.IsChecked && (bool)chkReadBuffer.IsChecked)
                {
                    //ReadBuffer with Tam2
                    tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, MemoryProfile,
                                                                   (ushort)Convert.ToUInt32(txtReadStartAddr.Text), (ushort)Convert.ToUInt32(txtReadLength.Text), false);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 256, tam2Auth);

                    Response = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    //swap the bytes
                    for (int i = 0; i < Response.Length; i += 2)
                    {
                        SwapBytes(ref Response, i, i + 1);
                    }
                    Challenge                  = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblDataValue.Content       = DecryptCustomData(Response.Skip(16).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1), Response.Skip(0).Take(16).ToArray());
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == false)
                {
                    //Auth with tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == true)
                {
                    //Readbuffer with Tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, false);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    Response = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    //swap the bytes
                    for (int i = 0; i < Response.Length; i += 2)
                    {
                        SwapBytes(ref Response, i, i + 1);
                    }
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    lblDataValue.Content       = "";
                }
                else
                {
                    //Authenticate with tam2
                    tam2Auth = new Gen2.NXP.AES.Tam2Authentication(Gen2.NXP.AES.KeyId.KEY1, Key1, Ichallenge, MemoryProfile,
                                                                   (ushort)Convert.ToUInt32(txtReadStartAddr.Text), (ushort)Convert.ToUInt32(txtReadLength.Text), true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam2Auth);
                    Response = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    if (Response != null)
                    {
                        lblTam2DataValue.Content = ByteFormat.ToHex(Response, "", " ");
                    }
                    lblTam2DataValue.Content = DecryptCustomData(Response.Skip(16).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1), Response.Skip(0).Take(16).ToArray());
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key1)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                }
                returnedIchallenge = new ushort[Challenge.Length / 2];
                returnedIchallenge = ByteConv.ToU16s(Challenge);
                if (returnedIchallenge.SequenceEqual(Ichallenge))
                {
                    MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
Exemple #2
0
        /// <summary>
        /// Authenticate with key0
        /// </summary>
        private void btnAuthKeyZero_Click(object sender, RoutedEventArgs e)
        {
            //Gen2.NXP.AES.Tam2Authentication tam2Auth;
            Gen2.NXP.AES.Tam1Authentication tam1Auth;
            ushort[] Key0, Ichallenge, returnedIchallenge;
            byte[]   Response, Challenge;
            lblDataValue.Content       = "";
            lblTam2DataValue.Content   = "";
            lblChallenge1Value.Content = "";

            switch (cbxReadDataBank.Text)
            {
            case "TID":
                MemoryProfile = Gen2.NXP.AES.Profile.TID;
                break;

            case "User":
                MemoryProfile = Gen2.NXP.AES.Profile.USER;
                break;

            case "EPC":
                MemoryProfile = Gen2.NXP.AES.Profile.EPC;
                break;
            }

            if (txtbxVerifyKeyZero.Text.Length == 32)
            {
                byte[] KeytoWrite = ByteFormat.FromHex(txtbxVerifyKeyZero.Text);
                Key0 = new ushort[KeytoWrite.Length / 2];
                Key0 = ByteConv.ToU16s(KeytoWrite);
            }
            else
            {
                MessageBox.Show("Please input valid Key0", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            byte[] randmNumber = ByteFormat.FromHex(lblRandomChallengeValue.Content.ToString().Replace(" ", ""));
            Ichallenge = new ushort[randmNumber.Length / 2];
            Ichallenge = ByteConv.ToU16s(randmNumber);
            try
            {
                if ((bool)chkReadData.IsChecked && (bool)chkReadBuffer.IsChecked)
                {
                    //ReadBuffer with Tam2
                    MessageBox.Show("Operation is not supported", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == false)
                {
                    //Authentication with tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, true);
                    Gen2.NXP.AES.Authenticate auth = new Gen2.NXP.AES.Authenticate(tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(auth, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key0)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    returnedIchallenge         = new ushort[Challenge.Length / 2];
                    returnedIchallenge         = ByteConv.ToU16s(Challenge);
                    byte[] generatedIChallenge = new byte[10];
                    byte[] tempBuffer          = new byte[16];
                    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                    Array.Copy(Response, 10, tempBuffer, 0, 16);
                    byte[] receivedIChallenge = DecryptIchallenge(tempBuffer, ByteConv.ConvertFromUshortArray(Key0).ToArray());
                    Array.Copy(receivedIChallenge, 6, receivedIChallenge, 0, 10);
                    Array.Resize(ref receivedIChallenge, 10);
                    if (generatedIChallenge.SequenceEqual(receivedIChallenge))
                    {
                        MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else if (chkReadData.IsChecked == false && chkReadBuffer.IsChecked == true)
                {
                    //Read Buffer with Tam1
                    tam1Auth = new Gen2.NXP.AES.Tam1Authentication(Gen2.NXP.AES.KeyId.KEY0, Key0, true);
                    Gen2.ReadBuffer buffer = new Gen2.NXP.AES.ReadBuffer(0, 128, tam1Auth);
                    Response  = (byte[])objReader.ExecuteTagOp(buffer, searchSelect);
                    Challenge = DecryptIchallenge(Response.Skip(0).Take(16).ToArray(), ByteConv.ConvertFromUshortArray(Key0)).Skip(6).Take(10).ToArray();
                    lblChallenge1Value.Content = ByteFormat.ToHex(Challenge, "", " ");
                    lblDataValue.Content       = "";
                    byte[] generatedIChallenge = new byte[10];
                    byte[] tempBuffer          = new byte[16];
                    Array.Copy(Response, 0, generatedIChallenge, 0, 10);
                    Array.Copy(Response, 10, tempBuffer, 0, 16);
                    byte[] receivedIChallenge = DecryptIchallenge(tempBuffer, ByteConv.ConvertFromUshortArray(Key0));
                    Array.Copy(receivedIChallenge, 6, receivedIChallenge, 0, 10);
                    Array.Resize(ref receivedIChallenge, 10);
                    if (generatedIChallenge.SequenceEqual(receivedIChallenge))
                    {
                        MessageBox.Show("Tag Successfully Authenticated", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        MessageBox.Show("Tag Failed Authentication; Confirm Verification Key is Correct.", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
                else
                {
                    //Authenticate with tam2
                    MessageBox.Show("Operation is not supported", "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Universal Reader Assistant", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }