예제 #1
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));
     }
 }
예제 #2
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));
 }
예제 #3
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));
        }
예제 #4
0
 public void Decrypt_InvalidIV()
 {
     Assert.Throws <CryptographicException>(() => RijndaelHelpers.Decrypt(_encryptedString, _passPhrase, _saltValue, "IV"));
 }
예제 #5
0
 public void Decrypt_InvalidCipherText()
 {
     Assert.Throws <FormatException>(() => RijndaelHelpers.Decrypt("abc", "PassPhrase", "SaltValue", "IV"));
 }