Exemple #1
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            Buffer.BlockCopy(buffer, 0, _nonce, 0, 12);
            count = SecretBox.Decrypt(buffer, offset, count, _buffer, 0, _nonce, _secretKey);
            var newBuffer = new byte[count];

            Buffer.BlockCopy(_buffer, 0, newBuffer, 0, count);
            _queuedData.Add(newBuffer);
        }
Exemple #2
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            unchecked
            {
                if (_nonce[3]++ == byte.MaxValue)
                {
                    _nonce[2]++;
                }

                _timestamp += (uint)_samplesPerFrame;
                _nonce[4]   = (byte)(_timestamp >> 24);
                _nonce[5]   = (byte)(_timestamp >> 16);
                _nonce[6]   = (byte)(_timestamp >> 8);
                _nonce[7]   = (byte)(_timestamp >> 0);
            }

            count = SecretBox.Encrypt(buffer, offset, count, _buffer, 12, _nonce, _secretKey);
            Buffer.BlockCopy(_nonce, 0, _buffer, 0, 12); //Copy the RTP header from nonce to buffer
            _audioClient.Send(_buffer, count + 12);
        }
        public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            unchecked
            {
                if (_nonce[3]++ == byte.MaxValue)
                {
                    _nonce[2]++;
                }

                _timestamp += (uint)_samplesPerFrame;
                _nonce[4]   = (byte)(_timestamp >> 24);
                _nonce[5]   = (byte)(_timestamp >> 16);
                _nonce[6]   = (byte)(_timestamp >> 8);
                _nonce[7]   = (byte)(_timestamp >> 0);
            }

            count = SecretBox.Encrypt(buffer, offset, count, _buffer, 12, _nonce, _secretKey);
            Buffer.BlockCopy(_nonce, 0, _buffer, 0, 12); //Copy the RTP header from nonce to buffer
            await _target.SendAsync(_buffer, count + 12).ConfigureAwait(false);
        }