// key can be expended for HMAC - i.e. a small key, e.g. 32 bytes, is still accepted as valid // the HMAC class already deals with keys larger than what it can use (digested to right size) 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"); } } } }
static MachineKeySection() { decryptionProp = new ConfigurationProperty("decryption", typeof(string), "Auto", PropertyHelper.WhiteSpaceTrimStringConverter, PropertyHelper.NonEmptyStringValidator, ConfigurationPropertyOptions.None); decryptionKeyProp = new ConfigurationProperty("decryptionKey", typeof(string), "AutoGenerate,IsolateApps", PropertyHelper.WhiteSpaceTrimStringConverter, PropertyHelper.NonEmptyStringValidator, ConfigurationPropertyOptions.None); validationProp = new ConfigurationProperty("validation", typeof(MachineKeyValidation), MachineKeyValidation.SHA1, new MachineKeyValidationConverter(), PropertyHelper.DefaultValidator, ConfigurationPropertyOptions.None); validationKeyProp = new ConfigurationProperty("validationKey", typeof(string), "AutoGenerate,IsolateApps", PropertyHelper.WhiteSpaceTrimStringConverter, PropertyHelper.NonEmptyStringValidator, ConfigurationPropertyOptions.None); properties = new ConfigurationPropertyCollection(); properties.Add(decryptionProp); properties.Add(decryptionKeyProp); properties.Add(validationProp); properties.Add(validationKeyProp); MachineKeySectionUtils.AutoGenKeys(); }
internal SymmetricAlgorithm GetDecryptionAlgorithm () { string name; if (decryption_key_name == null || decryption_key_name.StartsWith ("AutoGenerate")) name = "Auto"; else name = decryption_key_name; return MachineKeySectionUtils.GetDecryptionAlgorithm (name); }
internal void SetDecryptionKey (string key) { if ((key == null) || key.StartsWith ("AutoGenerate")) { decryption_key = AutoGenerate (MachineKeyRegistryStorage.KeyType.Encryption); } else { try { decryption_key = MachineKeySectionUtils.GetBytes (key, key.Length); DecryptionTemplate.Key = decryption_key; } catch { decryption_key = null; throw new ArgumentException ("Invalid key length"); } } }
internal KeyedHashAlgorithm GetValidationAlgorithm() { // code location to help with unit testing the code return(MachineKeySectionUtils.GetValidationAlgorithm(this)); }
internal SymmetricAlgorithm GetDecryptionAlgorithm() { // code location to help with unit testing the code return(MachineKeySectionUtils.GetDecryptionAlgorithm(Decryption)); }