System.Web.Configuration.MachineKeySection.SetValidationKey C# (CSharp) Method

SetValidationKey() static private method

static private SetValidationKey ( string key ) : void
key string
return void
		void SetValidationKey (string key)
		{
			if ((key == null) || key.StartsWith ("AutoGenerate")) {
				validation_key = AutoGenerate (MachineKeyRegistryStorage.KeyType.Validation);
			} else {
				try {
					validation_key = MachineKeySectionUtils.GetBytes (key, key.Length);
					ValidationTemplate.Key = validation_key;
				}
				catch (CryptographicException) {
					// second chance, use the key length that the HMAC really wants
					try {
						byte[] expanded_key = new byte [ValidationTemplate.Key.Length];
						Array.Copy (validation_key, 0, expanded_key, 0, validation_key.Length);
						ValidationTemplate.Key = expanded_key;
						validation_key = expanded_key;
					}
					catch {
						validation_key = null;
						throw new ArgumentException ("Invalid key length");
					}
				}
			}
		}