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

Org.BouncyCastle.Security.ParameterUtilities

public static class ParameterUtilities
Helpers for building ICipherParameters values: creating algorithm-appropriate KeyParameter instances, decoding ASN.1 algorithm parameters into IV-bearing ICipherParameters, generating random IV/parameter blocks, and wrapping/unwrapping ParametersWithRandom / ParametersWithContext envelopes.
public static KeyParameter CreateKeyParameter(DerObjectIdentifier algOid, byte[] keyBytes)

Build a KeyParameter for the algorithm identified by algOid.

public static KeyParameter CreateKeyParameter(string algorithm, byte[] keyBytes)

Build a KeyParameter for the named algorithm.

public static KeyParameter CreateKeyParameter(DerObjectIdentifier algOid, byte[] keyBytes, int offset, int length)

Build a KeyParameter from a slice of keyBytes.

public static KeyParameter CreateKeyParameter(string algorithm, byte[] keyBytes, int offset, int length)

Build a KeyParameter from a slice of keyBytes. DES / DES-EDE / RC2 keys are returned as their dedicated parameter subclasses; all other algorithms get a plain KeyParameter.

Generate a fresh ASN.1-encoded algorithm parameters block (typically a random IV) for the algorithm identified by algID.

public static Asn1Encodable GenerateParameters(string algorithm, SecureRandom random)

Generate a fresh ASN.1-encoded algorithm parameters block for the named algorithm. CAST5, IDEA and RC2 receive their dedicated parameter structures; other IV-based algorithms get a plain Asn1OctetString containing the IV.

public static string GetCanonicalAlgorithmName(string algorithm)

Returns the canonical algorithm name for the given alias or OID string, or null if the algorithm is not recognised.

Combine a key with ASN.1-encoded algorithm parameters, returning the appropriate ICipherParameters envelope (e.g. ParametersWithIV or AeadParameters for AES-GCM/CCM).

public static ICipherParameters GetCipherParameters(string algorithm, ICipherParameters key, Asn1Object asn1Params)

Combine a key with ASN.1-encoded algorithm parameters for the named algorithm. See the OID overload.

public static ICipherParameters GetContext(ICipherParameters cipherParameters, int minLen, int maxLen, out byte context)

Unwrap a ParametersWithContext envelope, returning the inner parameters and copying the context bytes out via context. If the envelope is absent, context is set to null and the input is returned unchanged.

public static ICipherParameters GetRandom(ICipherParameters cipherParameters, out SecureRandom random)

Unwrap a ParametersWithRandom envelope, returning the inner parameters and exposing the attached SecureRandom via random. If the envelope is absent, random is set to null and the input is returned unchanged.

public static ICipherParameters IgnoreRandom(ICipherParameters cipherParameters)

Strip any ParametersWithRandom envelope and return the inner parameters; otherwise return the input unchanged.

public static ICipherParameters WithContext(ICipherParameters cp, byte[] context)

Wrap cp in a ParametersWithContext envelope when context is non-null; otherwise return cp unchanged.

Wrap cp in a ParametersWithRandom envelope when random is non-null; otherwise return cp unchanged.