/// <summary>
 /// Instantiates an new instance with the data from the <paramref name="configuration"/>.
 /// </summary>
 /// <param name="configuration">The configuration to use to populate the new instance.</param>
 public StackableEncryptor(Configuration.IConfigurationGroup configuration)
     : this()
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     if (configuration.Key != "Encryptor")
     {
         throw new ArgumentException($"Wrong configuration. Configuration Key must equal \"Encryptor\". Configuration Key={configuration.Key}", nameof(configuration));
     }
     // EncryptorConfigurations
     if (!configuration.ContainsKey("EncryptorConfigurations"))
     {
         throw new ArgumentException($"Configuration missing subgroup. Configuration must have subgroup: \"EncryptorConfigurations\".", nameof(configuration));
     }
     _EncryptorConfigurations = new List <IEncryptorConfiguration>();
     foreach (var item in configuration["EncryptorConfigurations"])
     {
         // TODO: change this configuration item name to HashAlgorithmType to be consistent
         // HashAlgorithm
         var hashAlgorithmType = Type.GetType((string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "HashAlgorithm", typeof(Type)).Value);
         // Salt
         var    saltValue = (string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "Salt", typeof(string)).Value;
         byte[] salt      = Convert.FromBase64String(saltValue);
         // PasswordSaltHash
         var    passwordSaltHashValue = (string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "PasswordSaltHash", typeof(string)).Value;
         byte[] passwordSaltHash      = Convert.FromBase64String(passwordSaltHashValue);
         // SymmetricAlgorithmType
         Type            symmetricAlgorithmType = Type.GetType((string)Core.Configuration.ConfigurationHelper.FindConfigurationItem(configuration, "SymmetricAlgorithmType", typeof(Type)).Value);
         ISaltedPassword saltedPassword         = new SaltedPassword(hashAlgorithmType, passwordSaltHash, salt);
         var             dude = new EncryptorConfiguration(saltedPassword, symmetricAlgorithmType);
         _EncryptorConfigurations.Add(dude);
     }
 }
示例#2
0
        /// <summary>
        /// Determines if the <paramref name="candidatePassword"/> is valid for this <see cref="SaltedPassword"/>.
        /// </summary>
        /// <param name="candidatePassword">The password to check.</param>
        /// <returns><b>True</b> if the <paramref name="candidatePassword"/> matches the password that created this <see cref="SaltedPassword"/>; otherwise, <b>false</b> indicates a negative match.</returns>
        public bool IsValid(System.Security.SecureString candidatePassword)
        {
            if (candidatePassword == null)
            {
                throw new ArgumentNullException(nameof(candidatePassword));
            }
            var dude = new SaltedPassword(HashAlgorithmType, candidatePassword, Salt);

            return(IsValid(dude));
        }