public void DecryptFileAndVerify_DecryptWithWrongKey(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); TestFactory testFactory2 = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); testFactory2.Arrange(KeyType.Generated, FileType.Known); PGP pgp = new PGP(); // Act pgp.EncryptFileAndSign(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); var ex = Assert.Throws <PgpException>(() => pgp.DecryptFileAndVerify(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory2.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password)); string decryptedContent = File.ReadAllText(testFactory.DecryptedContentFilePath); // Assert Assert.Equal("Failed to verify file.", ex.Message); Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.True(File.Exists(testFactory.DecryptedContentFilePath)); Assert.Equal(string.Empty, decryptedContent.Trim()); // Teardown testFactory.Teardown(); }
private void Do() { using (PGP pgp = new PGP()) { // Encrypt file var inputPath = @"Messages\message.txt"; var encryptedMessage = "Messages\\message_by_package.txt.asc"; var publicKey = "Keys\\publicKey3072.asc"; var myPrivateKey = "Keys\\secretKey3072.asc"; var myPassword = "******"; pgp.EncryptFileAndSign(inputPath, encryptedMessage, publicKey, myPrivateKey, myPassword, true, true); pgp.DecryptFileAndVerify(encryptedMessage, $"{DateTime.UtcNow:yyyyMMddHHmm}.txt", publicKey, myPrivateKey, myPassword); } }
public void DecryptFileAndVerify_DecryptSignedAndEncryptedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); PGP pgp = new PGP(); // Act pgp.EncryptFileAndSign(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); pgp.DecryptFileAndVerify(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); string decryptedContent = File.ReadAllText(testFactory.DecryptedContentFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.True(File.Exists(testFactory.DecryptedContentFilePath)); Assert.Equal(testFactory.Content, decryptedContent.Trim()); // Teardown testFactory.Teardown(); }