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:
Return type:

Microsoft.AspNetCore.DataProtection.IDataProtector

Returns:

An Microsoft.AspNetCore.DataProtection.IDataProtector tied to the provided purpose chain.

public static IDataProtector CreateProtector(this IDataProtectionProvider provider, IEnumerable<string> purposes)
CreateProtector(Microsoft.AspNetCore.DataProtection.IDataProtectionProvider, System.String, System.String[])

Creates an Microsoft.AspNetCore.DataProtection.IDataProtector given a list of purposes.

Arguments:
Return type:

Microsoft.AspNetCore.DataProtection.IDataProtector

Returns:

An Microsoft.AspNetCore.DataProtection.IDataProtector tied to the provided purpose chain.

public static IDataProtector CreateProtector(this IDataProtectionProvider provider, string purpose, params string[] subPurposes)
GetDataProtectionProvider(System.IServiceProvider)

Retrieves an Microsoft.AspNetCore.DataProtection.IDataProtectionProvider from an System.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 an System.IServiceProvider given a list of purposes.

Arguments:
  • services (System.IServiceProvider) – An System.IServiceProvider which contains 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:

Microsoft.AspNetCore.DataProtection.IDataProtector

Returns:

An Microsoft.AspNetCore.DataProtection.IDataProtector tied to the provided purpose chain.

public static IDataProtector GetDataProtector(this IServiceProvider services, IEnumerable<string> purposes)
GetDataProtector(System.IServiceProvider, System.String, System.String[])

Retrieves an Microsoft.AspNetCore.DataProtection.IDataProtector from an System.IServiceProvider given a list of purposes.

Arguments:
Return type:

Microsoft.AspNetCore.DataProtection.IDataProtector

Returns:

An Microsoft.AspNetCore.DataProtection.IDataProtector tied to the provided purpose chain.

public static IDataProtector GetDataProtector(this IServiceProvider services, string purpose, params string[] subPurposes)
Protect(Microsoft.AspNetCore.DataProtection.IDataProtector, System.String)

Cryptographically protects a piece of plaintext data.

Arguments:
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:
Return type:

System.String

Returns:

The plaintext form of the protected data.

public static string Unprotect(this IDataProtector protector, string protectedData)