Exemple #1
0
        static Stream Process(Stream stream, string encryptionKey, CryptoStreamMode mode)
        {
            // TEMP
            return(stream);

            // TEMP

            if (stream.Length == 0)
            {
                return(stream);
            }

            var copy = new MemoryStream();

            stream.Position = 0;
            stream.CopyTo(copy);
            copy.Seek(0, SeekOrigin.Begin);

            switch (mode)
            {
            case CryptoStreamMode.Write:
                return(StreamCrypto.Encrypt(encryptionKey, copy));

            case CryptoStreamMode.Read:
                return(StreamCrypto.Decrypt(encryptionKey, copy));

            default:
                return(stream);
            }
        }
        protected void InitKey(string password)
        {
            byte[] passbuf = Encoding.UTF8.GetBytes(password);
            // init master key
            if (masterKey == null)
            {
                masterKey = new byte[keyLen];
            }

            if (masterKey.Length != keyLen)
            {
                Array.Resize(ref masterKey, keyLen);
            }

            StreamCrypto.LegacyDeriveKey(passbuf, masterKey, keyLen);
            // init session key
            sessionKey = new byte[keyLen];
        }