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!!"); }
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!!"); }
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!!!"); } }
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)); }
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!!"); }