System.Web.Configuration.MachineKeyConfig.AutoGenerate C# (CSharp) Method

AutoGenerate() private method

private AutoGenerate ( System.Web.Configuration.MachineKeyRegistryStorage type ) : byte[]
type System.Web.Configuration.MachineKeyRegistryStorage
return byte[]
		byte[] AutoGenerate (MachineKeyRegistryStorage.KeyType type)
		{
			byte[] key = null;
#if TARGET_J2EE
			{
#else
			try {
				key = MachineKeyRegistryStorage.Retrieve (type);

				// ensure the stored key is usable with the selection algorithm
				if (type == MachineKeyRegistryStorage.KeyType.Encryption)
					DecryptionTemplate.Key = key;
				else if (type == MachineKeyRegistryStorage.KeyType.Validation)
					ValidationTemplate.Key = key;
			} catch (Exception) {
				key = null;
			}
#endif
			// some algorithms have special needs for key (e.g. length, parity, weak keys...) 
			// so we better ask them to provide a default key (than to generate/use bad ones)
			if (key == null) {
				if (type == MachineKeyRegistryStorage.KeyType.Encryption)
					key = DecryptionTemplate.Key;
				else if (type == MachineKeyRegistryStorage.KeyType.Validation)
					key = ValidationTemplate.Key;
#if !TARGET_J2EE
				MachineKeyRegistryStorage.Store (key, type);
#endif
			}
			return key;
		}
	}
}