Ejemplo n.º 1
0
 public void Decrypt_NullInputs()
 {
     Assert.Throws <ArgumentNullException>(() => RijndaelHelpers.Decrypt(null, null, null, null));
     Assert.Throws <ArgumentNullException>(() => RijndaelHelpers.Decrypt(_encryptedString, null, null, null));
     Assert.Throws <ArgumentNullException>(() => RijndaelHelpers.Decrypt(_encryptedString, _passPhrase, null, null));
     Assert.Throws <ArgumentNullException>(() => RijndaelHelpers.Decrypt(_encryptedString, _passPhrase, _saltValue, null));
 }
Ejemplo n.º 2
0
 static void RijndaelDecrypt(string data, string passPhrase, string saltValue, string initializationValue, bool showHelp)
 {
     if (showHelp)
     {
         List <Parameter> parms = new List <Parameter>
         {
             new Parameter {
                 Key = "data", Type = typeof(string), HelpText = "Text to decrypt"
             },
             new Parameter {
                 Key = "pass", Type = typeof(string), HelpText = "Pass phrase"
             },
             new Parameter {
                 Key = "salt", Type = typeof(string), HelpText = "Salt value"
             },
             new Parameter {
                 Key = "iv", Type = typeof(string), HelpText = "Initialization vector"
             }
         };
         ConsoleColor defaultColor = Console.ForegroundColor;
         Console_WriteLine($"Parameter options for Rijndael decrypt:\r\n", ConsoleColor.Green);
         WriteMethodParametersHelp(parms);
         Console.ForegroundColor = defaultColor;
     }
     else
     {
         Console.WriteLine("Decrypting data using Rijndael algorithm.\r\n");
         Console.WriteLine(RijndaelHelpers.Decrypt(data, passPhrase, saltValue, initializationValue));
     }
 }
Ejemplo n.º 3
0
 public void Encrypt_NullInputs()
 {
     Assert.Throws <ArgumentNullException>(() => RijndaelHelpers.Encrypt(null, null, null, null));
     Assert.Throws <ArgumentNullException>(() => RijndaelHelpers.Encrypt(_plaintext, null, null, null));
     Assert.Throws <ArgumentNullException>(() => RijndaelHelpers.Encrypt(_plaintext, _passPhrase, null, null));
     Assert.Throws <ArgumentNullException>(() => RijndaelHelpers.Encrypt(_plaintext, _passPhrase, _saltValue, null));
 }
Ejemplo n.º 4
0
        public void EncryptDecrypt()
        {
            string _encryptedText = RijndaelHelpers.Encrypt(_plaintext, _passPhrase, _saltValue, _iv);

            Assert.IsNotEmpty(_encryptedText);
            Assert.AreEqual(_plaintext, RijndaelHelpers.Decrypt(_encryptedText, _passPhrase, _saltValue, _iv));
            // test with non base64 string
            Assert.Throws <FormatException>(() => RijndaelHelpers.Decrypt(_encryptedText + "x", _passPhrase, _saltValue, _iv));
        }
Ejemplo n.º 5
0
 public void Decrypt_InvalidIV()
 {
     Assert.Throws <CryptographicException>(() => RijndaelHelpers.Decrypt(_encryptedString, _passPhrase, _saltValue, "IV"));
 }
Ejemplo n.º 6
0
 public void Decrypt_InvalidCipherText()
 {
     Assert.Throws <FormatException>(() => RijndaelHelpers.Decrypt("abc", "PassPhrase", "SaltValue", "IV"));
 }
Ejemplo n.º 7
0
 public void Encrypt_InvalidIV()
 {
     Assert.Throws <CryptographicException>(() => RijndaelHelpers.Encrypt(_plaintext, _passPhrase, _saltValue, "IV"));
 }