DataProtectionCommonExtensions Class¶
Helpful extension methods for data protection APIs.
- Namespace
Microsoft.AspNetCore.DataProtection
- Assemblies
- Microsoft.AspNetCore.DataProtection.Abstractions
Syntax¶
public class DataProtectionCommonExtensions
-
class
Microsoft.AspNetCore.DataProtection.
DataProtectionCommonExtensions
Methods¶
-
CreateProtector
(Microsoft.AspNetCore.DataProtection.IDataProtectionProvider, System.Collections.Generic.IEnumerable<System.String>)¶ Creates an
Microsoft.AspNetCore.DataProtection.IDataProtector
given a list of purposes.Arguments: - provider (Microsoft.AspNetCore.DataProtection.IDataProtectionProvider) – The
Microsoft.AspNetCore.DataProtection.IDataProtectionProvider
from which to generate the purpose chain. - purposes (System.Collections.Generic.IEnumerable<System.String>) – The list of purposes which contribute to the purpose chain. This list must contain at least one element, and it may not contain null elements.
Return type: Returns: An
Microsoft.AspNetCore.DataProtection.IDataProtector
tied to the provided purpose chain.public static IDataProtector CreateProtector(this IDataProtectionProvider provider, IEnumerable<string> purposes)
- provider (Microsoft.AspNetCore.DataProtection.IDataProtectionProvider) – The
-
CreateProtector
(Microsoft.AspNetCore.DataProtection.IDataProtectionProvider, System.String, System.String[]) Creates an
Microsoft.AspNetCore.DataProtection.IDataProtector
given a list of purposes.Arguments: - provider (Microsoft.AspNetCore.DataProtection.IDataProtectionProvider) – The
Microsoft.AspNetCore.DataProtection.IDataProtectionProvider
from which to generate the purpose chain. - purpose (System.String) – The primary purpose used to create the
Microsoft.AspNetCore.DataProtection.IDataProtector
. - subPurposes (System.String<System.String>[]) – An optional list of secondary purposes which contribute to the purpose chain. If this list is provided it cannot contain null elements.
Return type: Returns: An
Microsoft.AspNetCore.DataProtection.IDataProtector
tied to the provided purpose chain.public static IDataProtector CreateProtector(this IDataProtectionProvider provider, string purpose, params string[] subPurposes)
- provider (Microsoft.AspNetCore.DataProtection.IDataProtectionProvider) – The
-
GetDataProtectionProvider
(System.IServiceProvider)¶ Retrieves an
Microsoft.AspNetCore.DataProtection.IDataProtectionProvider
from anSystem.IServiceProvider
.Arguments: services (System.IServiceProvider) – The service provider from which to retrieve the Microsoft.AspNetCore.DataProtection.IDataProtectionProvider
.Return type: Microsoft.AspNetCore.DataProtection.IDataProtectionProvider Returns: An Microsoft.AspNetCore.DataProtection.IDataProtectionProvider
. This method is guaranteed never to return null.public static IDataProtectionProvider GetDataProtectionProvider(this IServiceProvider services)
-
GetDataProtector
(System.IServiceProvider, System.Collections.Generic.IEnumerable<System.String>)¶ Retrieves an
Microsoft.AspNetCore.DataProtection.IDataProtector
from anSystem.IServiceProvider
given a list of purposes.Arguments: - services (System.IServiceProvider) – An
System.IServiceProvider
which contains theMicrosoft.AspNetCore.DataProtection.IDataProtectionProvider
from which to generate the purpose chain. - purposes (System.Collections.Generic.IEnumerable<System.String>) – The list of purposes which contribute to the purpose chain. This list must contain at least one element, and it may not contain null elements.
Return type: Returns: An
Microsoft.AspNetCore.DataProtection.IDataProtector
tied to the provided purpose chain.public static IDataProtector GetDataProtector(this IServiceProvider services, IEnumerable<string> purposes)
- services (System.IServiceProvider) – An
-
GetDataProtector
(System.IServiceProvider, System.String, System.String[]) Retrieves an
Microsoft.AspNetCore.DataProtection.IDataProtector
from anSystem.IServiceProvider
given a list of purposes.Arguments: - services (System.IServiceProvider) – An
System.IServiceProvider
which contains theMicrosoft.AspNetCore.DataProtection.IDataProtectionProvider
from which to generate the purpose chain. - purpose (System.String) – The primary purpose used to create the
Microsoft.AspNetCore.DataProtection.IDataProtector
. - subPurposes (System.String<System.String>[]) – An optional list of secondary purposes which contribute to the purpose chain. If this list is provided it cannot contain null elements.
Return type: Returns: An
Microsoft.AspNetCore.DataProtection.IDataProtector
tied to the provided purpose chain.public static IDataProtector GetDataProtector(this IServiceProvider services, string purpose, params string[] subPurposes)
- services (System.IServiceProvider) – An
-
Protect
(Microsoft.AspNetCore.DataProtection.IDataProtector, System.String)¶ Cryptographically protects a piece of plaintext data.
Arguments: - protector (Microsoft.AspNetCore.DataProtection.IDataProtector) – The data protector to use for this operation.
- plaintext (System.String) – The plaintext data to protect.
Return type: System.String
Returns: The protected form of the plaintext data.
public static string Protect(this IDataProtector protector, string plaintext)
-
Unprotect
(Microsoft.AspNetCore.DataProtection.IDataProtector, System.String)¶ Cryptographically unprotects a piece of protected data.
Arguments: - protector (Microsoft.AspNetCore.DataProtection.IDataProtector) – The data protector to use for this operation.
- protectedData (System.String) – The protected data to unprotect.
Return type: System.String
Returns: The plaintext form of the protected data.
public static string Unprotect(this IDataProtector protector, string protectedData)
-