示例#1
0
        private bool MapData()
        {
            Base = new Base();
            byte[] dataBytes = ReadAllBytes();

            string dataStr;
            if (EncryptionKey != null)//decrypt
            {
                CryptoBase crypto = new CryptoBase(EncryptionKey);
                if (dataBytes.Length < CryptoBase.IVLength)
                    return false;
                if (!crypto.DecryptAll(dataBytes, out dataStr))
                    return false;
            }
            else
            {
                if (dataBytes.Length == 0)
                    return false;
                dataStr = Encoding.ASCII.GetString(dataBytes);
            }

            Base = Serializer.Deserialize(dataStr);
            return true;
        }
示例#2
0
        public bool WriteChanges()
        {
            CryptoBase crypto = new CryptoBase(EncryptionKey);

            string xmlToSerialize = Serializer.Serialize(Base);

            byte[] toWrite;

            if (EncryptionKey != null)
            {
                toWrite = crypto.EncryptAll(xmlToSerialize);
            }
            else
            {
                toWrite = Encoding.ASCII.GetBytes(xmlToSerialize);
            }

            try
            {
                using (FileStream fsStream = new FileStream(Path, FileMode.Create))
                {
                    fsStream.Write(toWrite, 0, toWrite.Length);
                }
            }
            catch (Exception ex)
            {
                return false;
            }

            LastUpdated = DateTime.Now;
            return true;
        }