Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class Microsoft.​IdentityModel.​Tokens.​CryptoProviderFactory

Assembly: Microsoft.IdentityModel.Tokens

Inheritance: object → CryptoProviderFactory

Creates cryptographic operators by specifying a <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> 's and algorithms.

Properties

public static CryptoProviderFactory
Default
Returns the default <see cref="T:Microsoft.IdentityModel.Tokens.CryptoProviderFactory" /> instance.
public static bool
DefaultCacheSignatureProviders
Gets or sets the default value for caching of <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> 's.
public static int
DefaultSignatureProviderObjectPoolCacheSize
Gets or sets the maximum size of the object pool used by the SignatureProvider that are used for crypto objects.
CryptoProviderCache
Gets the <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CryptoProviderCache" /> .
CustomCryptoProvider
Extensibility point for creating custom cryptographic operators.
Remarks By default, if set, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> will be called before creating cryptographic operators. If true is returned, then <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> will be called. The <see cref="T:Microsoft.IdentityModel.Tokens.CryptoProviderFactory" /> will throw if the Cryptographic operator returned is not of the correct type.
public bool
CacheSignatureProviders
Gets or sets a bool controlling if <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> should be cached.
public int
SignatureProviderObjectPoolCacheSize
Gets or sets the maximum size of the object pool used by the SignatureProvider that are used for crypto objects.

Methods

CreateAuthenticatedEncryptionProvider​(SecurityKey key, string algorithm)
Creates an instance of <see cref="T:Microsoft.IdentityModel.Tokens.AuthenticatedEncryptionProvider" /> for a specific <paramref name="key" /> and <paramref name="algorithm" /> .
Returns An instance of <see cref="T:Microsoft.IdentityModel.Tokens.AuthenticatedEncryptionProvider" /> .
key The <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> to use.
algorithm The algorithm to use.
Remarks <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:Microsoft.IdentityModel.Tokens.AuthenticatedEncryptionProvider" />. </para> <para>Once done with the <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" />, call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseKeyWrapProvider(Microsoft.IdentityModel.Tokens.KeyWrapProvider)" />.</para>
CreateKeyWrapProvider​(SecurityKey key, string algorithm)
Creates an instance of <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" /> for a specific <paramref name="key" /> and <paramref name="algorithm" /> .
Returns An instance of <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" /> .
key The <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> to use.
algorithm The algorithm to use.
Remarks <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" />. </para> <para>Once done with the <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" />, call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseKeyWrapProvider(Microsoft.IdentityModel.Tokens.KeyWrapProvider)" />.</para>
CreateKeyWrapProviderForUnwrap​(SecurityKey key, string algorithm)
Creates an instance of <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" /> for a specific <paramref name="key" /> and <paramref name="algorithm" /> .
Returns An instance of <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" /> .
key The <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> to use.
algorithm The algorithm to use.
Remarks <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" />. </para> <para>Once done with the <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" />, call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseKeyWrapProvider(Microsoft.IdentityModel.Tokens.KeyWrapProvider)" />.</para>
CreateForSigning​(SecurityKey key, string algorithm)
Creates a <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> for signing with the specified <paramref name="key" /> and <paramref name="algorithm" /> .
Returns A <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> instance that can be used to create a signature.
key The <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> to use for signing.
algorithm The algorithm to use for signing.
Remarks <para>AsymmetricSignatureProviders require access to a PrivateKey for signing.</para> <para>Once done with the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" />, call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseSignatureProvider(Microsoft.IdentityModel.Tokens.SignatureProvider)" />.</para> <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" />. </para>
CreateForSigning​(SecurityKey key, string algorithm, bool cacheProvider)
Creates a <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> for signing with the specified <paramref name="key" /> and <paramref name="algorithm" /> .
Returns A <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> instance that can be used to create a signature.
key The <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> to use for signing.
algorithm The algorithm to use for signing.
cacheProvider Indicates whether the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> should be cached for reuse.
Remarks <para>AsymmetricSignatureProviders require access to a PrivateKey for signing.</para> <para>Once done with the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" />, call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseSignatureProvider(Microsoft.IdentityModel.Tokens.SignatureProvider)" />.</para> <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" />. </para>
CreateForVerifying​(SecurityKey key, string algorithm)
Creates a <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> for verifying signatures with the specified <paramref name="key" /> and <paramref name="algorithm" /> .
Returns A <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> instance that can be used to validate signatures using the <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> and algorithm.
key The <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> to use for signature verification.
algorithm The algorithm to use for verifying signatures.
Remarks <para>Once done with the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" />, call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseSignatureProvider(Microsoft.IdentityModel.Tokens.SignatureProvider)" />.</para> <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" />. </para>
CreateForVerifying​(SecurityKey key, string algorithm, bool cacheProvider)
Creates a <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> for verifying signatures with the specified <paramref name="key" /> and <paramref name="algorithm" /> .
Returns A <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> instance that can be used to validate signatures using the <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> and algorithm.
key The <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> to use for signature verification.
algorithm The algorithm to use for verifying signatures.
cacheProvider Specifies whether the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> should be cached for reuse.
Remarks <para>Once done with the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" />, call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseSignatureProvider(Microsoft.IdentityModel.Tokens.SignatureProvider)" />.</para> <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" />. </para>
CreateHashAlgorithm​(System.​Security.​Cryptography.​HashAlgorithmName algorithm)
Creates a <see cref="T:System.Security.Cryptography.HashAlgorithm" /> instance for a specific hash algorithm.
Returns A <see cref="T:System.Security.Cryptography.HashAlgorithm" /> instance that corresponds to the specified <paramref name="algorithm" /> .
algorithm The name of the hash algorithm to create.
Remarks <para>Once done with the <see cref="T:System.Security.Cryptography.HashAlgorithm" />, call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseHashAlgorithm(System.Security.Cryptography.HashAlgorithm)" />.</para> <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:System.Security.Cryptography.HashAlgorithm" />. </para>
CreateHashAlgorithm​(string algorithm)
Creates a <see cref="T:System.Security.Cryptography.HashAlgorithm" /> instance for a specific hash algorithm.
Returns A <see cref="T:System.Security.Cryptography.HashAlgorithm" /> instance that corresponds to the specified <paramref name="algorithm" /> .
algorithm The name of the hash algorithm to create.
Remarks Once done with the <see cref="T:System.Security.Cryptography.HashAlgorithm" /> , call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseHashAlgorithm(System.Security.Cryptography.HashAlgorithm)" /> . <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:System.Security.Cryptography.HashAlgorithm" />. </para>
CreateKeyedHashAlgorithm​(byte[] keyBytes, string algorithm)
Creates a <see cref="T:System.Security.Cryptography.KeyedHashAlgorithm" /> instance for a specific keyed hash algorithm.
Returns A <see cref="T:System.Security.Cryptography.KeyedHashAlgorithm" /> instance that corresponds to the specified <paramref name="algorithm" /> .
keyBytes The bytes to use as the key for the keyed hash.
algorithm The name of the keyed hash algorithm to create.
Remarks Once done with the <see cref="T:System.Security.Cryptography.KeyedHashAlgorithm" /> , call <see cref="M:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.ReleaseHashAlgorithm(System.Security.Cryptography.HashAlgorithm)" /> . <para>If <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true, <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.Create(System.String,System.Object[])" /> is called to obtain the <see cref="T:System.Security.Cryptography.KeyedHashAlgorithm" />. </para>
public bool
IsSupportedAlgorithm​(string algorithm)
Determines whether the specified hash algorithm is supported.
Returns <see langword="true" /> if: <list type="bullet"> <item> <description> <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true,</description> </item> <item> <description>The algorithm is supported.</description> </item> </list> Otherwise, <see langword="false" /> .
algorithm The name of the hash algorithm.
Remarks Considers only known hash algorithms.
public bool
IsSupportedAlgorithm​(string algorithm, SecurityKey key)
Checks if the specified algorithm and <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> are supported.
Returns <see langword="true" /> if: <list type="bullet"> <item> <description> <see cref="P:Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CustomCryptoProvider" /> is set and <see cref="M:Microsoft.IdentityModel.Tokens.ICryptoProvider.IsSupportedAlgorithm(System.String,System.Object[])" /> returns true,</description> </item> <item> <description>The algorithm / key pair is supported.</description> </item> </list> Otherwise, <see langword="false" /> .
algorithm The security algorithm to be used.
key The <see cref="T:Microsoft.IdentityModel.Tokens.SecurityKey" /> .
Remarks Algorithms are supported for specific key types. For example: <list type="bullet"> <item> <description> <see cref="F:Microsoft.IdentityModel.Tokens.SecurityAlgorithms.RsaSha256" /> and <see cref="T:Microsoft.IdentityModel.Tokens.RsaSecurityKey" /> will return true.</description> </item> <item> <description> <see cref="F:Microsoft.IdentityModel.Tokens.SecurityAlgorithms.RsaSha256" /> and <see cref="T:Microsoft.IdentityModel.Tokens.SymmetricSecurityKey" /> will return false.</description> </item> </list>
public void
ReleaseHashAlgorithm​(System.​Security.​Cryptography.​HashAlgorithm hashAlgorithm)
Releases resources associated with a <see cref="T:System.Security.Cryptography.HashAlgorithm" /> instance. The default behavior is to call <see cref="M:System.Security.Cryptography.HashAlgorithm.Dispose" /> .
hashAlgorithm The <see cref="T:System.Security.Cryptography.HashAlgorithm" /> instance to release.
public void
ReleaseKeyWrapProvider​(KeyWrapProvider provider)
Releases resources associated with a <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" /> instance.
provider The <see cref="T:Microsoft.IdentityModel.Tokens.KeyWrapProvider" /> instance to release.
public void
ReleaseRsaKeyWrapProvider​(RsaKeyWrapProvider provider)
Releases resources associated with an <see cref="T:Microsoft.IdentityModel.Tokens.RsaKeyWrapProvider" /> instance.
provider The <see cref="T:Microsoft.IdentityModel.Tokens.RsaKeyWrapProvider" /> instance to release.
public void
ReleaseSignatureProvider​(SignatureProvider signatureProvider)
Releases resources associated with a <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> instance.
signatureProvider The <see cref="T:Microsoft.IdentityModel.Tokens.SignatureProvider" /> instance to release.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object