Ejemplo n.º 1
0
        /// <summary>
        ///     Initialises a new instance of the <see cref="MacStream" /> class.
        /// </summary>
        /// <param name="binding">Stream to write to or read from.</param>
        /// <param name="writing">If set to <c>true</c>, writing; otherwise, reading.</param>
        /// <param name="function">MAC function to instantiate.</param>
        /// <param name="key">Cryptographic key to use in the MAC operation.</param>
        /// <param name="salt">Cryptographic salt to use in the MAC operation, if any.</param>
        /// <param name="nonce"></param>
        /// <param name="closeOnDispose">If set to <c>true</c>, bound stream will be closed on dispose/close.</param>
        /// <param name="config"></param>
        public MacStream(Stream binding, bool writing, MacFunction function, byte[] key, byte[] salt = null,
                         byte[] config = null, byte[] nonce = null, bool closeOnDispose = true)
        {
            Contract.Requires <ArgumentNullException>(binding != null);
            Contract.Requires <ArgumentNullException>(key != null);

            _streamBinding  = binding;
            Writing         = writing;
            _closeOnDispose = closeOnDispose;

            _mac    = AuthenticatorFactory.CreateMacPrimitive(function, key, salt, config, nonce);
            _output = new byte[_mac.OutputSize];
            _buffer = new byte[BufferSize];
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="HashStream" /> class.
        /// </summary>
        /// <param name="binding">Stream to write to or read from.</param>
        /// <param name="writing">If set to <c>true</c>, writing; otherwise, reading.</param>
        /// <param name="function">Hash/digest function to instantiate.</param>
        /// <param name="output">Byte array where the finished hash will be output to.</param>
        /// <param name="closeOnDispose">If set to <c>true</c>, bound stream will be closed on dispose/close.</param>
        public HashStream(Stream binding, bool writing, HashFunction function, out byte[] output,
                          bool closeOnDispose = true)
        {
            Contract.Requires <ArgumentNullException>(binding != null);

            _streamBinding  = binding;
            Writing         = writing;
            _closeOnDispose = closeOnDispose;

            _digest = AuthenticatorFactory.CreateHashPrimitive(function);
            _buffer = new byte[BufferSize];
            _output = new byte[_digest.OutputSize];
            output  = _output;
        }
Ejemplo n.º 3
0
        public HashStream(Stream binding, bool writing, IAuthenticationConfiguration config,
                          bool closeOnDispose = true)
        {
            Contract.Requires(binding != null);

            _streamBinding  = binding;
            Writing         = writing;
            _closeOnDispose = closeOnDispose;

            if (config.FunctionType != AuthenticationFunctionType.Mac)
            {
                throw new ConfigurationInvalidException("Configuration specifies function type other than MAC.");
            }

            _digest = AuthenticatorFactory.CreateHashPrimitive(config.FunctionName.ToEnum <HashFunction>());
            _buffer = new byte[BufferSize];
            _output = new byte[_digest.OutputSize];
        }
Ejemplo n.º 4
0
        public MacStream(Stream binding, bool writing, IAuthenticationConfiguration config, byte[] key,
                         bool closeOnDispose = true)
        {
            Contract.Requires <ArgumentNullException>(binding != null);
            Contract.Requires <ArgumentNullException>(key != null);

            _streamBinding  = binding;
            Writing         = writing;
            _closeOnDispose = closeOnDispose;

            if (config.FunctionType != AuthenticationFunctionType.Mac)
            {
                throw new ConfigurationInvalidException("Configuration specifies function type other than MAC.");
            }

            _mac = AuthenticatorFactory.CreateMacPrimitive(config.FunctionName.ToEnum <MacFunction>(), key, config.Salt,
                                                           config.FunctionConfiguration, config.Nonce);
            _output = new byte[_mac.OutputSize];
        }