本文整理汇总了C#中System.Web.Configuration.MachineKeySection类的典型用法代码示例。如果您正苦于以下问题:C# MachineKeySection类的具体用法?C# MachineKeySection怎么用?C# MachineKeySection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MachineKeySection类属于System.Web.Configuration命名空间,在下文中一共展示了MachineKeySection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MachineKeyMasterKeyProvider
// the only required parameter is 'machineKeySection'; other parameters are just used for unit testing
internal MachineKeyMasterKeyProvider(MachineKeySection machineKeySection, string applicationId = null, string applicationName = null, CryptographicKey autogenKeys = null, KeyDerivationFunction keyDerivationFunction = null) {
_machineKeySection = machineKeySection;
_applicationId = applicationId;
_applicationName = applicationName;
_autogenKeys = autogenKeys;
_keyDerivationFunction = keyDerivationFunction;
}
示例2: Initialize
public override void Initialize(string name, NameValueCollection config)
{
if (config == null) throw new ArgumentException("config");
if (String.IsNullOrEmpty(name)) name = DEFAULT_PROVIDER_NAME;
base.Initialize(name, config);
applicationName = ConfigurationHelper.GetConfigStringValueOrDefault(config, ConfigurationHelper.CONFIG_APPLICATION_NAME_FIELD, System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
description = ConfigurationHelper.GetConfigStringValueOrDefault(config, ConfigurationHelper.CONFIG_DESCRIPTION_FIELD, "Couch DB Membership Provider");
enablePasswordReset = ConfigurationHelper.GetConfigBoolValueOrDefault(config, ConfigurationHelper.CONFIG_ENABLE_PASSWORD_RESET, false);
enablePasswordRetrieval = false;
maxInvalidPasswordAttempts = ConfigurationHelper.GetConfigIntValueOrDefault(config, ConfigurationHelper.CONFIG_MAX_INVALID_PASSWORD_ATTEMPTS, 5);
minRequiredNonAlphanumericCharacters = ConfigurationHelper.GetConfigIntValueOrDefault(config, ConfigurationHelper.CONFIG_MIN_REQUIRED_NON_ALPHANUMERIC_CHARACTERS, 0);
minRequiredPasswordLength = ConfigurationHelper.GetConfigIntValueOrDefault(config, ConfigurationHelper.CONFIG_MIN_REQUIRED_PASSWORD_LENGTH, 8);
passwordAttemptWindow = ConfigurationHelper.GetConfigIntValueOrDefault(config, ConfigurationHelper.CONFIG_PASSWORD_ATTEMPT_WINDOW, 10);
passwordFormat = MembershipPasswordFormat.Hashed;
passwordStrengthRegularExpression = ConfigurationHelper.GetConfigStringValueOrDefault(config, ConfigurationHelper.CONFIG_PASSWORD_STRENGTH_REGULAR_EXPRESSION, String.Empty);
requiresQuestionAndAnswer = ConfigurationHelper.GetConfigBoolValueOrDefault(config, ConfigurationHelper.CONFIG_REQUIRES_QUESTION_AND_ANSWER, false);
requiresUniqueEmail = true;
providerName = name;
couchDbServerName = ConfigurationHelper.MembershipCouchDbServerName;
couchDbServerPort = ConfigurationHelper.MembershipCouchDbServerPort;
couchDbDatabaseName = ConfigurationHelper.MembershipCouchDbDatabaseName;
if (String.IsNullOrEmpty(couchDbDatabaseName))
throw new ProviderException(Strings.CouchDbConfigurationDatabaseNameMissing);
machineKeySection = (MachineKeySection)WebConfigurationManager.GetWebApplicationSection("system.web/machineKey");
if(machineKeySection == null)
throw new ProviderException(Strings.HashedPasswordsRequireMachineKey);
if (machineKeySection.ValidationKey.ToLower().Contains("Autogenerate".ToLower()))
throw new ProviderException(Strings.HashedPasswordsRequireMachineKey);
}
示例3: UniMembershipProvider
public UniMembershipProvider()
{
pApplicationName = "unicloud";
pName = "UniMembershipProvider";
Configuration cfg = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
machineKey = (MachineKeySection)cfg.GetSection("system.web/machineKey");
}
示例4: Encrypt_RoundTrip
public void Encrypt_RoundTrip (MachineKeySection section)
{
byte [] data = new byte [14];
byte [] encdata = MachineKeySectionUtils.Encrypt (section, data);
byte [] decdata = MachineKeySectionUtils.Decrypt (section, encdata);
Assert.AreEqual (data, decdata, "roundtrip");
// changing length (missing first byte)
byte [] cut = new byte [encdata.Length - 1];
Array.Copy (encdata, 1, cut, 0, cut.Length);
Assert.IsNull (MachineKeySectionUtils.Decrypt (section, cut), "bad length");
// changing last byte (padding)
byte be = encdata [encdata.Length - 1];
encdata [encdata.Length - 1] = ChangeByte (be);
byte[] result = MachineKeySectionUtils.Decrypt (section, encdata);
// this will return null if a bad padding is detected - OTOH since we're using a random key and we
// encrypt a random IV it's possible the decrypted stuff will randomly have a "valid" padding (there's
// only so much possible values and the bots runs those tests pretty often and give false positive)
// To avoid this we fallback to ensure the data is invalid (if should be empty)
int total = 0;
if (result != null) {
for (int i=0; i < result.Length; i++)
total += result [i];
}
Assert.IsTrue (result == null || total != 0, "bad padding");
}
示例5: Decryption_RC2
public void Decryption_RC2 ()
{
MachineKeySection section = new MachineKeySection ();
Assert.AreEqual ("Auto", section.Decryption, "before");
section.Decryption = "alg:RC2";
Assert.AreEqual ("alg:RC2", section.Decryption, "after");
}
示例6: AccountManagement
public AccountManagement()
{
// Get encryption and decryption key information from the configuration.
Configuration cfg =
WebConfigurationManager.OpenWebConfiguration(
System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
machineKey = (MachineKeySection) cfg.GetSection("system.web/machineKey");
formsConfig = (AuthenticationSection) cfg.GetSection("system.web/authentication");
}
示例7: Decryption_InvalidName
public void Decryption_InvalidName ()
{
MachineKeySection section = new MachineKeySection ();
Assert.AreEqual ("Auto", section.Decryption, "before");
section.Decryption = "alg:UnexistingType";
// looks like the problem is found (much) later
Assert.AreEqual ("alg:UnexistingType", section.Decryption, "Decryption");
}
示例8: GetMachineKeySection
protected override MachineKeySection GetMachineKeySection()
{
var mk = new MachineKeySection();
mk.DecryptionKey = "0A5D40CA5C48726556180200D9DBE44A8FE58A8E6A3E8CC153BFC631833BA0FE";
mk.ValidationKey = "7D30287B722BF7141915476F0609FFD604CBB5243D8574F85BA5B496FA58D3EE49A8CE1E07E958F145967495A56E5B6298082070C0488F7B4FC42EDE9956422E";
mk.Validation = MachineKeyValidation.SHA1;
mk.Decryption = "AES";
return mk;
}
示例9: GetMachineKey_MachineKeyConfigured_ReturnsMachineKey
public void GetMachineKey_MachineKeyConfigured_ReturnsMachineKey()
{
var config = new MachineKeySection { ValidationKey = MachineKeyValidation };
var helper = new MachineKeyConfigurationHelper(config);
var key = helper.GetMachineKey();
Assert.AreEqual(_expectedMachineKey, key);
}
示例10: UniMembershipProvider
public UniMembershipProvider()
{
_pApplicationName = "unicloud";
_pName = "UniMembershipProvider";
var cfg = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath);
_machineKey = (MachineKeySection) cfg.GetSection("system.web/machineKey");
_userRepository = UniContainer.Resolve<IUserRepository>();
_userRoleRepository = UniContainer.Resolve<IUserRoleRepository>();
}
示例11: DefaultValues
public void DefaultValues ()
{
MachineKeySection section = new MachineKeySection ();
Assert.AreEqual (MachineKeyCompatibilityMode.Framework20SP1, section.CompatibilityMode, "CompatibilityMode");
Assert.AreEqual ("Auto", section.Decryption, "Decryption");
Assert.AreEqual ("AutoGenerate,IsolateApps", section.DecryptionKey, "DecryptionKey");
Assert.AreEqual (MachineKeyValidation.HMACSHA256, section.Validation, "Validation");
Assert.AreEqual ("HMACSHA256", section.ValidationAlgorithm, "ValidationAlgorithm");
Assert.AreEqual ("AutoGenerate,IsolateApps", section.ValidationKey, "ValidationKey");
}
示例12: SecurityExtensions
/// <summary>
/// 静态构造方法。
/// </summary>
static SecurityExtensions()
{
var config = WebConfigurationManager.OpenWebConfiguration(HostingEnvironment.ApplicationVirtualPath);
MachineKey = (MachineKeySection)config.GetSection("system.web/machineKey");
if (MachineKey.Decryption == "Auto")
{
MachineKey.DecryptionKey = KeyCreator.CreateKey(0x18);
MachineKey.ValidationKey = KeyCreator.CreateKey(0x40);
}
}
示例13: AspNetCryptoServiceProvider
// This constructor is used only for testing purposes and by the singleton provider
// and should not otherwise be called during ASP.NET request processing.
internal AspNetCryptoServiceProvider(MachineKeySection machineKeySection = null, ICryptoAlgorithmFactory cryptoAlgorithmFactory = null, IMasterKeyProvider masterKeyProvider = null, IDataProtectorFactory dataProtectorFactory = null, KeyDerivationFunction keyDerivationFunction = null) {
_machineKeySection = machineKeySection;
_cryptoAlgorithmFactory = cryptoAlgorithmFactory;
_masterKeyProvider = masterKeyProvider;
_dataProtectorFactory = dataProtectorFactory;
_keyDerivationFunction = keyDerivationFunction;
// This CryptoServiceProvider is active if specified as such in the <system.web/machineKey> section
IsDefaultProvider = (machineKeySection != null && machineKeySection.CompatibilityMode >= MachineKeyCompatibilityMode.Framework45);
// The DataProtectorCryptoService is active if specified as such in config
_isDataProtectorEnabled = (machineKeySection != null && !String.IsNullOrWhiteSpace(machineKeySection.DataProtectorType));
}
示例14: NullableStringProperties
// It test all existing (as of r61933) configuration
// sections that use PropertyHelper.NonEmptyStringValidator.
public void NullableStringProperties ()
{
new AnonymousIdentificationSection ().CookieName = null;
new AnonymousIdentificationSection ().CookiePath = null;
new AssemblyInfo (null);
new BufferModeSettings (null, 0x10000, 0x1000, 10,
TimeSpan.FromMinutes (1),
TimeSpan.FromSeconds (30), 10);
new BuildProvider (null, null);
new ClientTarget (null, null);
new CodeSubDirectory (null);
new EventMappingSettings (null, null);
new ExpressionBuilder (null, null);
FormsAuthenticationConfiguration fac =
new FormsAuthenticationConfiguration ();
// I don't like this test though.
fac.DefaultUrl = null;
fac.LoginUrl = null;
fac.Name = null;
fac.Path = null;
new HttpHandlerAction (null, null, null);
new HttpModuleAction (null, null);
MachineKeySection mks = new MachineKeySection ();
// algorithms are limited
// mks.Decryption = null;
mks.DecryptionKey = null;
mks.ValidationKey = null;
new MembershipSection ().DefaultProvider = null;
new NamespaceInfo (null);
new OutputCacheProfile (null);
new ProfileSettings (null);
RoleManagerSection rms = new RoleManagerSection ();
rms.CookieName = null;
rms.CookiePath = null;
rms.DefaultProvider = null;
new RuleSettings (null, null, null);
new SqlCacheDependencyDatabase (null, null);
new TagMapInfo (null, null);
new TagPrefixInfo (null, null, null, null, null);
new TransformerInfo (null, null);
new TrustLevel (null, null);
new TrustSection ().Level = null;
new UrlMapping (null, null);
// WebControlsSection.ClientScriptsLocation is not settable
new WebPartsPersonalization ().DefaultProvider = null;
}
示例15: Encrypt_RoundTrip
public void Encrypt_RoundTrip (MachineKeySection section)
{
byte [] data = new byte [14];
byte [] encdata = MachineKeySectionUtils.Encrypt (section, data);
byte [] decdata = MachineKeySectionUtils.Decrypt (section, encdata);
Assert.AreEqual (data, decdata, "roundtrip");
// changing length (missing first byte)
byte [] cut = new byte [encdata.Length - 1];
Array.Copy (encdata, 1, cut, 0, cut.Length);
Assert.IsNull (MachineKeySectionUtils.Decrypt (section, cut), "bad length");
// changing last byte (padding)
byte be = encdata [encdata.Length - 1];
encdata [encdata.Length - 1] = ChangeByte (be);
Assert.IsNull (MachineKeySectionUtils.Decrypt (section, encdata), "bad padding");
}