示例#1
0
文件: Entrys.cs 项目: Dekkee/LavaAxe
        public void Deserialize(string fileName, byte[] file)
        {
            TLVUtil tlvParser = new TLVUtil();

            int curPos = 0;

            string name, data;

            while (curPos < file.Length)
            {
                //Чтение имени
                curPos = tlvParser.ReadKnownTag(file, curPos, Entry.ENTRY_NAME_TAG);
                if (tlvParser.TagData[1] != 0)
                    name = Encoding.GetEncoding(1251).GetString(file, curPos, tlvParser.TagData[1]);
                else
                    name = "";

                curPos += tlvParser.TagData[1];

                //Чтение тела файла
                curPos = tlvParser.ReadKnownTag(file, curPos, Entry.ENTRY_DATA_TAG);
                if (tlvParser.TagData[1] != 0)
                    data = Encoding.GetEncoding(1251).GetString(file, curPos, tlvParser.TagData[1]);
                else
                    data = "";

                curPos += tlvParser.TagData[1];

                Entry entry = new Entry(this, name, data, fileName);
                Blocks.Add(entry);

                if (ItemsChangedEvent != null)
                    ItemsChangedEvent(this, new ItemsChangedEventArgs(entry));
            }
        }
示例#2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (pbMasterPWord.Password != "")
            {
                byte[] container = proxy.GetContainer(name).Container;

                if (container == null)
                {
                    MessageBox.Show("Container not found");
                    return;
                }

                byte[] decipheredContainer = CryptoLibrary.decrypt28147cfb(CryptoLibrary.computeHash3411(Utility.StringToByteArray(pbMasterPWord.Password)), container);
                TLVUtil tlv = new TLVUtil();

                int curPos = tlv.ReadATag(decipheredContainer, 0);

                if (tlv.TagData[0] != 0x25)
                {
                    MessageBox.Show("Wrong password");
                    return;
                }

                if (tlv.TagData[1] != 32)
                {
                    MessageBox.Show("Bad key");
                    return;
                }

                if (key == null)
                    key = new byte[32];

                Array.Copy(decipheredContainer, curPos, key, 0, 32);

                this.Close();
            }
        }