Beispiel #1
0
        public void setValue2(TLVList tlvs)
        {
            tlvInit   = false;
            tlvValue  = null;
            tlvLength = 0;

            if (tlvs == null || secret == null)
            {
                return;
            }
            var Encoder = new MemoryStream();
            var os      = new BinaryWriter(Encoder);

            foreach (short or in order)
            {
                for (int i = 0; i < tlvs.Count(); i++)
                {
                    if (tlvs[i].tlvCode == or)
                    {
                        os.Write(tlvs[i].tlvValue);
                    }
                }
            }

            byte[] digest = hmacMd5(Encoder.ToArray(), Encoding.UTF8.GetBytes(secret));
            //BitConverter.GetBytes(this.secret));
            tlvValue  = digest;
            tlvLength = digest.Length;
            tlvInit   = true;
        }
Beispiel #2
0
 public TLVCMTSMIC(TLVList tlvs, String secret)
 {
     tlvLength   = 0;
     tlvCode     = 7;
     this.secret = secret;
     setValue2(tlvs);
 }
Beispiel #3
0
        public string Decode2File(string FileName)
        {
            var MS = new FileStream(FileName, FileMode.Open);

            BinaryFile = new byte[MS.Length];
            MS.Read(BinaryFile, 0, (int)MS.Length);
            EncodedFile = Decode(null, BinaryFile, itemSymbolTable);
            return(ToString());
        }
Beispiel #4
0
 public TLVCMMIC(TLVList tlvEncodings)
 {
     tlvLength = 0;
     tlvCode   = 6;
     if (tlvEncodings == null)
     {
         tlvValue = null;
     }
     setValue(tlvEncodings);
 }
Beispiel #5
0
        public byte[] Encode2File(string FileName, string strSecret)
        {
            EncodedFile = null;
            BinaryFile  = null;
            Secret      = strSecret;
            var MS = new FileStream(FileName, FileMode.Open);

            BinaryFile = new byte[MS.Length];
            MS.Read(BinaryFile, 0, (int)MS.Length);
            EncodedFile = Encode(null, (new UTF8Encoding()).GetString(BinaryFile), itemSymbolTable);
            return(ToEncoding());
        }
Beispiel #6
0
        private TLVList Decode(TLV Parent, byte[] binaryStructureFile, SymbolTable DocFile)
        {
            var newTlvList = new TLVList();
            int i          = 0;

            while (i < binaryStructureFile.Length - 1)
            {
                byte getItentification = binaryStructureFile[i++];
                int  sizeOfElement     = 0;
                if (getItentification == 64)
                {
                    sizeOfElement = (binaryStructureFile[i++] << 8) | binaryStructureFile[i++];
                }
                else
                {
                    sizeOfElement = binaryStructureFile[i++];
                }
                Param findParamElement   = getTLVCode(DocFile, getItentification);
                var   getContextToDecode = new byte[sizeOfElement];

                Array.Copy(binaryStructureFile, i, getContextToDecode, 0, sizeOfElement);
                i += sizeOfElement;
                if (findParamElement != null)
                {
                    bool itsGroup = findParamElement.Group != null ? true : false;
                    if (itsGroup)
                    {
                        //Get some solution for format activating difrent type of class
                        TLV newTlvElement = TLV.Create(findParamElement, getContextToDecode);
                        newTlvElement.setParent(Parent);
                        newTlvElement.children = Decode(newTlvElement, getContextToDecode, findParamElement.Group);
                        DebugEvent(ref newTlvElement);
                        newTlvList.Add(newTlvElement);
                    }
                    else
                    {
                        TLV newTlvElement = TLV.Create(findParamElement, getContextToDecode);
                        newTlvElement.setParent(Parent);
                        DebugEvent(ref newTlvElement);
                        newTlvList.Add(newTlvElement);
                    }
                }
                if (findParamElement == null)
                {
                    TLV newTlvElement = new TLVGeneric("GenericTLV", getItentification, getContextToDecode);
                    newTlvElement.setParent(Parent);
                    DebugEvent(ref newTlvElement);
                    newTlvList.Add(newTlvElement);
                }
            }
            return(newTlvList);
        }
Beispiel #7
0
 public string Decoding(byte[] DecodeString)
 {
     //try
     //{
     EncodedFile = null;
     BinaryFile  = null;
     EncodedFile = Decode(null, DecodeString, itemSymbolTable);
     return(ToString());
     //}
     //catch (Exception e)
     // {
     //    throw new Exception("Error ocurred at position : \n" + e.Message);
     //  }
 }
Beispiel #8
0
 public byte[] Encoding(string EncodeString, string strSecret)
 {
     //try
     //{
     EncodedFile = null;
     BinaryFile  = null;
     Secret      = strSecret;
     EncodedFile = Encode(null, EncodeString, itemSymbolTable);
     return(ToEncoding());
     //}
     //catch (Exception ex)
     //{
     //    throw new Exception("Error ocurred at position : \n" + LastCommand);
     // }
 }
Beispiel #9
0
        public void setValue(TLVList tlvEncodings)
        {
            tlvInit   = false;
            tlvValue  = null;
            tlvLength = 0;

            if (tlvEncodings == null)
            {
                return;
            }
            MD5 md5Hasher = MD5.Create();

            byte[] Master = tlvEncodings.GetEncodings();
            md5Hasher.ComputeHash(Master, 0, Master.Length);
            tlvValue = md5Hasher.Hash;
            string sResult = BitConverter.ToString(tlvValue);

            tlvLength = tlvValue.Length;
            tlvInit   = true;
        }
Beispiel #10
0
        private TLVList Encode(TLV Parent, string FileToParse, SymbolTable DocFile)
        {
            var NewTlvList = new TLVList();

            while (true)
            {
                int PosLine  = FileToParse.IndexOf(';');
                int PosGroup = FileToParse.IndexOf('{');
                if (PosLine < 0 && PosGroup < 0)
                {
                    break;
                }
                if (PosLine > PosGroup && PosGroup > -1)
                {
                    // Exclude Comment Before Began // # /* */
                    //We Find Post Group Recursive Call
                    string Name =
                        FileToParse.Substring(0, PosGroup).Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ').Trim
                            ();
                    if (Name.StartsWith("/*"))
                    {
                        Name = Name.Substring(Name.IndexOf("*/") + 2).Trim();
                    }
                    LastCommand = Name;
                    if (Name != "Main")
                    {
                        Param  FindElem      = DocFile[Name];
                        string FileToParse2  = Split(FileToParse.Substring(PosGroup));
                        string Manage        = FileToParse2.Substring(1, FileToParse2.Length - 2);
                        TLV    newTlvElement = TLV.Create(FindElem, "");
                        newTlvElement.setParent(Parent);
                        newTlvElement.children = Encode(newTlvElement, Manage, FindElem.Group);
                        FileToParse            = FileToParse.Substring(PosGroup + FileToParse2.Length);
                        NewTlvList.Add(newTlvElement);
                        DebugEvent(ref newTlvElement);
                    }
                    else
                    {
                        string FileToParse2 = Split(FileToParse.Substring(PosGroup));
                        string Manage       = FileToParse2.Substring(1, FileToParse2.Length - 2);
                        NewTlvList  = Encode(null, Manage, DocFile);
                        FileToParse = FileToParse.Substring(PosGroup + FileToParse2.Length);
                    }
                }
                else
                {
                    var    getRegEx = new Regex(@"\b.*?;");
                    string NewValue = getRegEx.Match(FileToParse).ToString().Replace('\t', ' ').Replace('\n', ' ');
                    // string NewVal = FileToParse.Substring(0, PosLine ).Trim();
                    string SymbolName = NewValue.Split(' ')[0];
                    LastCommand = SymbolName;
                    NewValue    = NewValue.Substring(SymbolName.Length + 1, NewValue.IndexOf(';') - SymbolName.Length - 1);
                    FileToParse = FileToParse.Substring(PosLine + 1);
                    if (SymbolName != "GenericTLV")
                    {
                        TLV NewTlvElement = TLV.Create(DocFile[SymbolName], NewValue);

                        NewTlvElement.setParent(Parent);
                        DebugEvent(ref NewTlvElement);
                        NewTlvList.Add(NewTlvElement);
                    }
                    else
                    {
                        TLV NewTlvElement = new TLVGeneric(SymbolName, NewValue);
                        NewTlvElement.setParent(Parent);
                        DebugEvent(ref NewTlvElement);
                        NewTlvList.Add(NewTlvElement);
                    }
                }
            }
            return(NewTlvList);
        }