示例#1
0
        protected override void WriteImpl(ReadOnlySpan <byte> source, long offset)
        {
            int  size        = source.Length;
            long sectorIndex = offset / SectorSize;

            if (_encryptor == null)
            {
                _encryptor = new Aes128XtsTransform(_key1, _key2, false);
            }

            source.CopyTo(_tempBuffer);
            _encryptor.TransformBlock(_tempBuffer, 0, size, (ulong)sectorIndex);

            base.WriteImpl(_tempBuffer.AsSpan(0, size), offset);
        }
示例#2
0
        protected override void ReadImpl(Span <byte> destination, long offset)
        {
            int  size        = destination.Length;
            long sectorIndex = offset / SectorSize;

            if (_decryptor == null)
            {
                _decryptor = new Aes128XtsTransform(_key1, _key2, true);
            }

            base.ReadImpl(_tempBuffer.AsSpan(0, size), offset);

            _decryptor.TransformBlock(_tempBuffer, 0, size, (ulong)sectorIndex);
            _tempBuffer.AsSpan(0, size).CopyTo(destination);
        }