public override byte[] ReadBytes(int count) { byte[] bytes = base.ReadBytes(count); if (autoAlignOn) { bytesSinceAlignStart += (uint)bytes.Length; } if (checksumCalculator?.CalculateForDecryptedData == false) { checksumCalculator?.AddBytes(bytes); } if (xorKey.HasValue) { for (int i = 0; i < count; i++) { bytes[i] = (byte)(bytes[i] ^ xorKey.Value); } } if (checksumCalculator?.CalculateForDecryptedData == true) { checksumCalculator?.AddBytes(bytes); } return(bytes); }
public override void Write(byte[] buffer) { if (buffer == null) { return; } var data = buffer; if (checksumCalculator?.CalculateForDecryptedData == true) { checksumCalculator?.AddBytes(data); } if (xorKey.HasValue) { // Avoid changing data in array, so create a copy data = new byte[buffer.Length]; Array.Copy(buffer, 0, data, 0, buffer.Length); for (int i = 0; i < data.Length; i++) { data[i] = (byte)(data[i] ^ xorKey.Value); } } if (checksumCalculator?.CalculateForDecryptedData == false) { checksumCalculator?.AddBytes(data); } base.Write(data); if (autoAlignOn) { bytesSinceAlignStart += (uint)data.Length; } }