public void ConfigureCryptoContainer_NullConfiguration_ArgumentNullExceptionThrown() { var testContainer = new RijndaelManaged(); SimpleAesEncryptionConfiguration invalidTestConfig = null; _target.ConfigureCryptoContainer(testContainer, invalidTestConfig); }
public void __init() { testConfig = new SimpleAesEncryptionConfiguration(); testConfig.EncryptionKey = new EncryptionKeyConfigurationElement(256, "3q2+796tvu/erb7v3q2+796tvu/erb7v3q2+796tvu8="); _target = new RijndaelMessageDecryptor(testConfig); }
/// <summary> /// Generates the encryption configuration. /// </summary> /// <param name="options">The commandline options to use for the encryption.</param> /// <returns>The configuration required for the Simple AES library</returns> public SimpleAesEncryptionConfiguration GenerateEncryptionConfiguration(LogDecryptOptions options) { SimpleAesEncryptionConfiguration result; if (string.IsNullOrWhiteSpace(options.Key)) { // No key is specified, read the whole config from file result = ConfigurationManager.GetSection(DEFAULT_CONFIG_SECTION_NAME) as SimpleAesEncryptionConfiguration; } else { // Use the command line options result = new SimpleAesEncryptionConfiguration() { CipherMode = options.Mode, Padding = options.Padding, EncryptionKey = new EncryptionKeyConfigurationElement() { KeySize = options.KeySize, Key = options.Key } }; } return(result); }
public void ConfigureCryptoContainer_NullEncryptionKey_CryptographicExceptionThrown() { var testContainer = new RijndaelManaged(); SimpleAesEncryptionConfiguration invalidTestConfig = new SimpleAesEncryptionConfiguration { EncryptionKey = null, }; _target.ConfigureCryptoContainer(testContainer, invalidTestConfig); }
public void ConfigureCryptoContainer_InvalidKeyLength_CryptographicExceptionThrown() { var testContainer = new RijndaelManaged(); SimpleAesEncryptionConfiguration invalidTestConfig = new SimpleAesEncryptionConfiguration { EncryptionKey = new EncryptionKeyConfigurationElement(255, Convert.ToBase64String(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF })), }; _target.ConfigureCryptoContainer(testContainer, invalidTestConfig); }
public void ConfigureCryptoContainer_IllegalKeySizeTooSmall_CryptographicExceptionThrown() { var testContainer = new RijndaelManaged(); SimpleAesEncryptionConfiguration invalidTestConfig = new SimpleAesEncryptionConfiguration { EncryptionKey = new EncryptionKeyConfigurationElement(127, "testKey"), }; _target.ConfigureCryptoContainer(testContainer, invalidTestConfig); }
public void ConfigureCryptoContainer_EmptyEncryptionKey_CryptographicExceptionThrown() { var testContainer = new RijndaelManaged(); SimpleAesEncryptionConfiguration invalidTestConfig = new SimpleAesEncryptionConfiguration { EncryptionKey = new EncryptionKeyConfigurationElement(256, string.Empty), }; _target.ConfigureCryptoContainer(testContainer, invalidTestConfig); }
public void ConstructorWithConfig_ConfigStoredInCorrectProperty_ConfigCanBeAccessed() { var localTestConfig = new SimpleAesEncryptionConfiguration(); localTestConfig.EncryptionKey = new EncryptionKeyConfigurationElement(256, "3q2+796tvu/erb7v3q2+796tvu/erb7v3q2+796tvu8="); var target = new RijndaelMessageDecryptor(localTestConfig); Assert.AreSame(localTestConfig, target.Configuration); }
public void ConfigureCryptoContainer_ValidConfiguration_ContainerIsConfigured() { var testContainer = new RijndaelManaged(); var testKey = new byte[32] { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF }; var validTestConfig = new SimpleAesEncryptionConfiguration() { EncryptionKey = new EncryptionKeyConfigurationElement(256, Convert.ToBase64String(testKey)), CipherMode = CipherMode.CBC, Padding = PaddingMode.ISO10126 }; _target.ConfigureCryptoContainer(testContainer, validTestConfig); Assert.IsTrue(testKey.SequenceEqual(testContainer.Key)); Assert.AreEqual(validTestConfig.CipherMode, testContainer.Mode); Assert.AreEqual(validTestConfig.Padding, testContainer.Padding); Assert.AreEqual(validTestConfig.EncryptionKey.KeySize, testContainer.KeySize); Assert.IsTrue(testContainer.IV.Length == 16); }
public void __init() { testConfig = new SimpleAesEncryptionConfiguration(); _target = new RijndaelMessageHandlerTestHarness(testConfig); }
public RijndaelMessageHandlerTestHarness(SimpleAesEncryptionConfiguration config) : base(config) { }
static void Main(string[] args) { int keySize = 256; // If the user specified a non default key length if (args.Any()) { // If there are missing or additional command-line parameters if (args.Length != 2) { ExitWithError(1); } // If the length switch was not selected if (!args[0].Equals("-L", StringComparison.OrdinalIgnoreCase)) { ExitWithError(1); } // Parse the keySize from the command-line parameters // If there was an error, exit if (string.IsNullOrWhiteSpace(args[1]) || !Int32.TryParse(args[1], out keySize)) { ExitWithError(1); } } Console.WriteLine("Generating a new key for Log4Net.MessageEncryptor: "); // Read the configuration file for the key size information SimpleAesEncryptionConfiguration config = new SimpleAesEncryptionConfiguration() { EncryptionKey = new EncryptionKeyConfigurationElement(keySize, "") }; using (RijndaelManaged cryptoContainer = new RijndaelManaged()) { var legalKeys = new [] { 128, 192, 256 }; // Validate KeySize if (!legalKeys.Contains(keySize)) { Console.WriteLine("Invalid Key size (" + keySize + ")"); Console.WriteLine("Valid Key sizes are: " + string.Join(", ", legalKeys)); return; } cryptoContainer.KeySize = config.EncryptionKey.KeySize; // Generates a new key using the standard .NET method of generating a new symmetric key cryptoContainer.GenerateKey(); var key = Convert.ToBase64String(cryptoContainer.Key); // Output the new key to the screen and the clipboard Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(); Console.WriteLine(key); Console.ResetColor(); } Console.WriteLine(); Console.WriteLine("Please press any key to exit."); Console.ReadKey(); }