示例#1
0
 public void PGPDecrypt_DecryptFile_EmptyKeyFileName_ThrowsException()
 {
     try
     {
         PSS_PGPDecrypt.DecryptFileAndOutputToFile("fillerdata", "", string.Empty);
     }
     catch (Exception e)
     {
         Assert.IsTrue(e is ArgumentNullException);
     }
 }
示例#2
0
        public void PGPEncryptDecryptFileStream_Works_Full_Pass()
        {
            var testFileName          = "testFile.txt";
            var testEncryptedFileName = "testFileEncrypted.txt";
            var testText = "This Message is to be Encrypted and then Decrypted. :)";

            if (File.Exists(testFileName))
            {
                File.Delete(testFileName);
            }

            if (File.Exists(testEncryptedFileName))
            {
                File.Delete(testEncryptedFileName);
            }

            File.Create(testFileName).Dispose();

            using (TextWriter tw = new StreamWriter(testFileName))
            {
                tw.WriteLine(testText);
            }

            var success = PSS_PGPEncrypt.PopulatePublicKey(PGP_Test_Variables.PublicKey);

            Assert.IsTrue(success, "Failed to populate Public Key from String!!!!");

            var fileInfo = new FileInfo(testFileName);

            PSS_PGPEncrypt.EncryptFile(fileInfo, testEncryptedFileName, false, false);

            Assert.IsTrue(PSS_PGPEncrypt.IsPublicKeyPopulated, "PSS_PGPEncrypt.IsPublicKeyPopulated Should be TRUE and isn't!!!");
            Assert.IsTrue(File.Exists(testEncryptedFileName), "No Encrypted File was found.  Encryption has failed.");

            var testFileText          = File.ReadAllText(testFileName);
            var testEncryptedFileText = File.ReadAllText(testEncryptedFileName);

            Assert.IsFalse(testFileText.Equals(testEncryptedFileText), "Encryption Failed the file contents are the same!!!");

            PSS_PGPDecrypt.PopulatedPrivateKeyAndPassword(PGP_Test_Variables.PrivateKey, PGP_Test_Variables.Passcode);

            using (var fileStream = new FileStream(testEncryptedFileName, FileMode.Open))
            {
                var decryptedStream = PSS_PGPDecrypt.DecryptStream(fileStream);

                var reader = new StreamReader(decryptedStream);

                var testResult = reader.ReadToEnd().Trim();

                Assert.IsTrue(testText.Equals(testResult), "Original Text should be the same as the decrypted text and its not!!!");
            }
        }
示例#3
0
 public void PGPDecrypt_DecryptFile_EmptyKeyInStream_ThrowsException()
 {
     try
     {
         using (Stream input = PSS_PGPEncrypt.StringToStream("TEST"), keyIn = null)
         {
             PSS_PGPDecrypt.DecryptFileAndOutputToFile(input, keyIn, string.Empty);
         }
     }
     catch (Exception e)
     {
         Assert.IsTrue(e is ArgumentNullException);
     }
 }
示例#4
0
        public void PGPEncryptDecryptFile_Works_Full_Pass()
        {
            var testFileName           = "testFile.txt";
            var testEncryptedFileName  = "testFileEncrypted.txt";
            var testDecryptedFileName  = "testFileDecrypted.txt";
            var testPrivateKeyFileName = "testPrivateKeyFile";
            var testText = "This Message is to be Encrypted and then Decrypted. :)";

            #region Cleanup from last run and setup for new
            if (File.Exists(testFileName))
            {
                File.Delete(testFileName);
            }

            if (File.Exists(testEncryptedFileName))
            {
                File.Delete(testEncryptedFileName);
            }

            if (File.Exists(testDecryptedFileName))
            {
                File.Delete(testDecryptedFileName);
            }

            if (File.Exists(testPrivateKeyFileName))
            {
                File.Delete(testPrivateKeyFileName);
            }

            File.Create(testFileName).Dispose();

            using (TextWriter tw = new StreamWriter(testFileName))
            {
                tw.WriteLine(testText);
            }

            File.Create(testPrivateKeyFileName).Dispose();

            using (TextWriter tw = new StreamWriter(testPrivateKeyFileName))
            {
                tw.WriteLine(PGP_Test_Variables.PrivateKey);
            }
            #endregion

            var success = PSS_PGPEncrypt.PopulatePublicKey(PGP_Test_Variables.PublicKey);

            Assert.IsTrue(success, "Failed to populate Public Key from String!!!!");

            var fileInfo = new FileInfo(testFileName);

            PSS_PGPEncrypt.EncryptFile(fileInfo, testEncryptedFileName, false, false);

            Assert.IsTrue(PSS_PGPEncrypt.IsPublicKeyPopulated, "PSS_PGPEncrypt.IsPublicKeyPopulated Should be TRUE and isn't!!!");
            Assert.IsTrue(File.Exists(testEncryptedFileName), "No Encrypted File was found.  Encryption has failed.");

            var testFileText          = File.ReadAllText(testFileName);
            var testEncryptedFileText = File.ReadAllText(testEncryptedFileName);

            Assert.IsFalse(testFileText.Equals(testEncryptedFileText), "Encryption Failed the file contents are the same!!!");

            PSS_PGPDecrypt.DecryptFileAndOutputToFile(testEncryptedFileName, testPrivateKeyFileName, PGP_Test_Variables.Passcode, testDecryptedFileName);

            var testFileDecrypted = File.ReadAllText(testDecryptedFileName);

            Assert.IsTrue(testFileDecrypted.Equals(testFileText), "Text from before encryption and after encryption should be the same. They were Not!!");
        }