// 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");
             }
         }
     }
 }
Exemple #2
0
		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");
				}
			}
		}