MachineKey.Protect(Byte[], String[]) Method (System.Web.Security) (2024)

Table of Contents
Remarks Applies to

Protects the specified data by encrypting or signing it.

public: static cli::array <System::Byte> ^ Protect(cli::array <System::Byte> ^ userData, ... cli::array <System::String ^> ^ purposes);
public static byte[] Protect (byte[] userData, params string[] purposes);
static member Protect : byte[] * string[] -> byte[]
Public Shared Function Protect (userData As Byte(), ParamArray purposes As String()) As Byte()

Parameters

userData
Byte[]

The data to protect. This data is passed as plaintext.

purposes
String[]

A list of purposes for the data. If this value is specified, the same list must be passed to the Unprotect(Byte[], String[]) method in order to decipher the returned ciphertext.

Returns

The ciphertext data.

Exceptions

The purposes array contains one or more white-space-only entries.

Remarks

This method supersedes the Encode method, which requires the caller to specify whether the plaintext data should be encrypted, signed, or both. The Protect method performs the appropriate operation and securely protects the data. Ciphertext data produced by this method can only be deciphered by the Unprotect method.

The purposes parameter is an optional list of reasons that can lock the ciphertext to a specific purpose. This parameter lets you isolate cryptographic operations performed by different subsystems within an application. A malicious client should not be able to get the result of one subsystem's Protect method and feed it as input to another subsystem's Unprotect method, which could compromise application security. The purposes parameter helps ensure that protected data can only be used by the component that originally generated it. Applications should make sure that each subsystem uses a unique purposes list.

For example, to protect or unprotect an authentication token, you could call the method using code like the following example:

MachineKey.Protect(..., "Authentication token"); MachineKey.Unprotect(..., "Authentication token"); 
MachineKey.Protect(..., "Authentication token") MachineKey.Unprotect(..., "Authentication token") 

Applications can dynamically generate the purposes parameter. In that case, prefix user-supplied values with a fixed value (like "Username: " + username) to minimize the risk of a malicious client crafting input that matches a token that is used by some other part of the system. Any dynamically-generated strings should come after fixed strings. For example, to protect or unprotect a private message that is tied to a specific user, use code like the following example:

MachineKey.Protect(..., "Private message", "Recipient: " + username); MachineKey.Unprotect(..., "Private message", "Recipient: " + username); 
MachineKey.Protect(..., "Private message", "Recipient: " + username) MachineKey.Unprotect(..., "Private message", "Recipient: " + username) 

When the Unprotect method is called, the value that is provided for the purposes parameter must be the same value that was provided to the Protect method. Otherwise the operation will fail with a CryptographicException exception.

The configuration settings that are required for the MachineKeyCompatibilityMode.Framework45 option are required for this method even if the MachineKeySection.CompatibilityMode property is not set to the Framework45 option.

Applies to

MachineKey.Protect(Byte[], String[]) Method (System.Web.Security) (2024)
Top Articles
How to find drinkable water in the wild
PADI Certification Card FAQs
Ups Customer Center Locations
Play FETCH GAMES for Free!
Nco Leadership Center Of Excellence
Midflorida Overnight Payoff Address
PontiacMadeDDG family: mother, father and siblings
Craglist Oc
Sissy Hypno Gif
Alpha Kenny Buddy - Songs, Events and Music Stats | Viberate.com
Zendaya Boob Job
Blue Beetle Showtimes Near Regal Swamp Fox
Discover Westchester's Top Towns — And What Makes Them So Unique
Bjork & Zhulkie Funeral Home Obituaries
Busted Barren County Ky
My Homework Lesson 11 Volume Of Composite Figures Answer Key
Hennens Chattanooga Dress Code
Delaware Skip The Games
Gran Turismo Showtimes Near Marcus Renaissance Cinema
8005607994
Cain Toyota Vehicles
F45 Training O'fallon Il Photos
When Does Subway Open And Close
Utexas Iot Wifi
Bidevv Evansville In Online Liquid
Https E22 Ultipro Com Login Aspx
4 Times Rihanna Showed Solidarity for Social Movements Around the World
Bolly2Tolly Maari 2
Mjc Financial Aid Phone Number
Delta Math Login With Google
Airg Com Chat
Max 80 Orl
What Time Does Walmart Auto Center Open
Wow Quest Encroaching Heat
Suspect may have staked out Trump's golf course for 12 hours before the apparent assassination attempt
Pickle Juiced 1234
Agematch Com Member Login
Yogu Cheshire
Registrar Lls
Homeloanserv Account Login
Shipping Container Storage Containers 40'HCs - general for sale - by dealer - craigslist
Skyward Cahokia
Unblocked Games 6X Snow Rider
The top 10 takeaways from the Harris-Trump presidential debate
Suzanne Olsen Swift River
Secondary Math 2 Module 3 Answers
How To Find Reliable Health Information Online
Lorcin 380 10 Round Clip
Generator für Fantasie-Ortsnamen: Finden Sie den perfekten Namen
The Ultimate Guide To 5 Movierulz. Com: Exploring The World Of Online Movies
Scholar Dollar Nmsu
Bellin Employee Portal
Latest Posts
Article information

Author: Greg O'Connell

Last Updated:

Views: 5592

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Greg O'Connell

Birthday: 1992-01-10

Address: Suite 517 2436 Jefferey Pass, Shanitaside, UT 27519

Phone: +2614651609714

Job: Education Developer

Hobby: Cooking, Gambling, Pottery, Shooting, Baseball, Singing, Snowboarding

Introduction: My name is Greg O'Connell, I am a delightful, colorful, talented, kind, lively, modern, tender person who loves writing and wants to share my knowledge and understanding with you.