Example #1
0
        public void PGPEncrypt_PopulateBadKey_FromString_Fails()
        {
            var success = PSS_PGPEncrypt.PopulatePublicKey(PGP_Test_Variables.Bad_PublicKey);

            Assert.IsFalse(success, "Populated a Public Key from a bad String and shouldn't!!!!");
            Assert.IsFalse(PSS_PGPEncrypt.IsPublicKeyPopulated, "PSS_PGPEncrypt.IsPublicKeyPopulated Should be FALSE and isn't!!");
        }
Example #2
0
        public void PGPEncrypt_PopulateKey_FromString_Works()
        {
            var success = PSS_PGPEncrypt.PopulatePublicKey(PGP_Test_Variables.PublicKey);

            Assert.IsTrue(success, "Failed to populate Public Key from String!!!!");
            Assert.IsTrue(PSS_PGPEncrypt.IsPublicKeyPopulated, "PSS_PGPEncrypt.IsPublicKeyPopulated Should be TRUE and isn't!!");
        }
Example #3
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!!!");
            }
        }
Example #4
0
        public void PGPEncrypt_Encrypt_Encrypts()
        {
            var success = PSS_PGPEncrypt.PopulatePublicKey(PGP_Test_Variables.PublicKey);

            var test_string = "Test this encryption!!!";

            var result = PSS_PGPEncrypt.EncryptBytes(Encoding.Default.GetBytes(test_string), true);

            var encryptedString = Encoding.ASCII.GetString(result);

            Assert.IsTrue(success, "Failed to populate Public Key from String!!!!");
            Assert.IsTrue(PSS_PGPEncrypt.IsPublicKeyPopulated, "PSS_PGPEncrypt.IsPublicKeyPopulated Should be TRUE and isn't!!");
            Assert.IsFalse(encryptedString.Contains(test_string));
        }
Example #5
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);
     }
 }
Example #6
0
        public void PGPEncrypt_StringToStream_StreamToStream_Works()
        {
            var       testString = "Did I live?";
            const int numRuns    = 30;

            var listOResults = new List <string>();

            for (var i = 0; i < numRuns; i++)
            {
                using (var streamTest = PSS_PGPEncrypt.StringToStream(i > 0?listOResults[i - 1]:testString))
                {
                    listOResults.Add(PSS_PGPEncrypt.StreamToString(streamTest));

                    Assert.IsTrue(testString.Equals(listOResults[i]),
                                  "String to Stream Should have produced the same string as the starting one and did not!!!");
                }
            }

            Assert.AreEqual(numRuns, listOResults.Count, "The number of successful executions should match the number of runs and did not!!!");
        }
Example #7
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!!");
        }