예제 #1
0
 public static string readEPCLabel(string strEPC, out ulong uEPCNumber)
 {
     try
     {
         string EPClabel     = RFIDTagInfo.HEXToASCII(strEPC.Substring(0, 6).ToUpper());
         string serialNumber = strEPC.Substring(7).Replace(" ", "");
         uEPCNumber = ulong.Parse(serialNumber);
         string EPSnumber = uEPCNumber.ToString("D20");
         return(EPClabel + EPSnumber);;
     }
     catch (Exception exp)
     {
         Trace.WriteLine("Get Exception " + exp.Message);
         uEPCNumber = 0;
         return("");
     }
 }
        public string DecryptFromHEX(string inputPart1, string inputPart2)
        {
            // Create AesManaged
            if (aes.Key == null || inputPart2 == "")
            {//can't covert 0x00 to ASCII word
                return("");
            }

            for (int j = 0; j < inputPart2.Length / 6; j++)
            {
                int pos = inputPart2.LastIndexOf("00");
                if (pos != -1)
                {
                    inputPart2 = inputPart2.Remove(pos - 3);
                }
                else
                {
                    break;
                }
            }

            for (int i = 0; i < 2; i++)
            {
                string hex2Ascii = "";
                string plaintext = "";
                try
                {
                    switch (decState)
                    {
                    case decryptedState.CombinedMemory:
                    {
                        hex2Ascii = RFIDTagInfo.HEXToASCII(
                            inputPart1 + inputPart2);

                        if (!IsBase64String(hex2Ascii))
                        {
                            //Trace.WriteLine("Format not support1 " + hex2Ascii);
                            decState = decryptedState.SingleMemroy;
                            continue;
                        }
                    }
                    break;

                    case decryptedState.SingleMemroy:
                    {
                        hex2Ascii = RFIDTagInfo.HEXToASCII(inputPart2);
                        if (!IsBase64String(hex2Ascii))
                        {
                            //Trace.WriteLine("Format not support2 " + inputPart2);
                            decState = decryptedState.CombinedMemory;
                            return("");
                        }
                    }
                    break;
                    }


                    //Trace.WriteLine("Read encrypted message " + hex2Ascii +
                    //                  ", decState = " + decState.ToString());
                    byte[] cipherText = System.Convert.FromBase64String(hex2Ascii);
                    plaintext = DecryptData(cipherText);

                    if (plaintext != "")
                    {
                        decState = decryptedState.CombinedMemory;
                        return(plaintext);
                    }
                }
                catch (Exception exp)  {   }
                switch (decState)
                {
                case decryptedState.CombinedMemory:
                    decState = decryptedState.SingleMemroy;
                    break;

                case decryptedState.SingleMemroy:
                    decState = decryptedState.CombinedMemory;
                    return("");
                }
            }
            return("");
        }