예제 #1
0
        /// <summary>
        /// LoadFromCache method implementation
        /// </summary>
        private static SIDsParametersRecord LoadFromCache()
        {
            SIDsParametersRecord config = null;

            if (!File.Exists(SystemUtilities.SystemCacheFile))
            {
                return(null);
            }
            DataContractSerializer serializer = new DataContractSerializer(typeof(SIDsParametersRecord));

            using (FileStream fs = new FileStream(SystemUtilities.SystemCacheFile, FileMode.Open, FileAccess.Read))
            {
                byte[] bytes = new byte[fs.Length];
                int    n     = fs.Read(bytes, 0, (int)fs.Length);
                fs.Close();

                byte[] byt = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    byt = aes.Decrypt(bytes);
                }
                using (MemoryStream ms = new MemoryStream(byt))
                {
                    using (StreamReader reader = new StreamReader(ms))
                    {
                        config = (SIDsParametersRecord)serializer.ReadObject(ms);
                    }
                }
            }
            return(config);
        }
예제 #2
0
            /// <summary>
            /// WriteMessage method override
            /// </summary>
            public override void WriteMessage(Message message, Stream stream)
            {
                byte[] cryptedBytes = new byte[stream.Length];
                stream.Read(cryptedBytes, 0, (int)stream.Length);
                byte[] unencryptedBytes = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    unencryptedBytes = aes.Decrypt(cryptedBytes);
                }
                MemoryStream stm = new MemoryStream(unencryptedBytes);

                innerEncoder.WriteMessage(message, stm);
                stream.Flush();
            }
예제 #3
0
            /// <summary>
            /// DecryptBuffer method implementation (decompress)
            /// </summary>
            private ArraySegment <byte> DecryptBuffer(ArraySegment <byte> buffer, BufferManager bufferManager)
            {
                byte[] cryptedBytes = new byte[buffer.Count];
                Array.Copy(buffer.Array, buffer.Offset, cryptedBytes, 0, cryptedBytes.Length);

                byte[] unencryptedBytes = null;
                using (AESSystemEncryption aes = new AESSystemEncryption())
                {
                    unencryptedBytes = aes.Decrypt(cryptedBytes);
                }

                int totalLength = unencryptedBytes.Length + buffer.Offset;

                byte[] bufferManagerBuffer = bufferManager.TakeBuffer(totalLength);
                Array.Clear(bufferManagerBuffer, 0, bufferManagerBuffer.Length);
                Array.Copy(buffer.Array, 0, bufferManagerBuffer, 0, buffer.Offset);
                Array.Copy(unencryptedBytes, 0, bufferManagerBuffer, buffer.Offset, unencryptedBytes.Length);

                ArraySegment <byte> byteArray = new ArraySegment <byte>(bufferManagerBuffer, buffer.Offset, unencryptedBytes.Length);

                bufferManager.ReturnBuffer(buffer.Array);

                return(byteArray);
            }