예제 #1
0
        public virtual void Serialize <T>(Stream output, T graph)
        {
            Logger.LogTrace(Messages.SerializingGraph, typeof(T));

            using (var rijndael = new RijndaelManaged())
            {
                rijndael.Key  = _encryptionKey;
                rijndael.Mode = CipherMode.CBC;
                rijndael.GenerateIV();

                using (ICryptoTransform encryptor = rijndael.CreateEncryptor())
                    using (var wrappedOutput = new IndisposableStream(output))
                        using (var encryptionStream = new CryptoStream(wrappedOutput, encryptor, CryptoStreamMode.Write))
                        {
                            wrappedOutput.Write(rijndael.IV, 0, rijndael.IV.Length);
                            _inner.Serialize(encryptionStream, graph);
                            encryptionStream.Flush();
                            encryptionStream.FlushFinalBlock();
                        }
            }
        }
예제 #2
0
        public virtual void Serialize <T>(Stream output, T graph)
        {
            Logger.Verbose(Messages.SerializingGraph, typeof(T));

            using (var aes = new AesManaged())
            {
                aes.Key  = _encryptionKey;
                aes.Mode = CipherMode.CBC;
                aes.GenerateIV();

                using (ICryptoTransform encryptor = aes.CreateEncryptor())
                    using (var wrappedOutput = new IndisposableStream(output))
                        using (var encryptionStream = new CryptoStream(wrappedOutput, encryptor, CryptoStreamMode.Write))
                        {
                            wrappedOutput.Write(aes.IV, 0, aes.IV.Length);
                            _inner.Serialize(encryptionStream, graph);
                            encryptionStream.Flush();
                            encryptionStream.FlushFinalBlock();
                        }
            }
        }