<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.1" />

ParametersWithContext

using System; namespace Org.BouncyCastle.Crypto.Parameters { public class ParametersWithContext : ICipherParameters { private readonly ICipherParameters m_parameters; private readonly byte[] m_context; public int ContextLength => m_context.Length; public ICipherParameters Parameters => m_parameters; internal static ICipherParameters ApplyOptionalContext(ICipherParameters parameters, byte[] context) { if (context != null) return new ParametersWithContext(parameters, context); return parameters; } public ParametersWithContext(ICipherParameters parameters, byte[] context) { if (context == null) throw new ArgumentNullException("context"); m_parameters = parameters; m_context = (byte[])context.Clone(); } public ParametersWithContext(ICipherParameters parameters, byte[] context, int contextOff, int contextLen) { if (context == null) throw new ArgumentNullException("context"); m_parameters = parameters; m_context = new byte[contextLen]; Array.Copy(context, contextOff, m_context, 0, contextLen); } private ParametersWithContext(ICipherParameters parameters, int contextLength) { if (contextLength < 0) throw new ArgumentOutOfRangeException("contextLength"); m_parameters = parameters; m_context = new byte[contextLength]; } public void CopyContextTo(byte[] buf, int off, int len) { if (m_context.Length != len) throw new ArgumentOutOfRangeException("len"); Array.Copy(m_context, 0, buf, off, len); } public byte[] GetContext() { return (byte[])m_context.Clone(); } } }