public async Task DecryptFileAndVerifyAsync_DecryptUnsignedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); TestFactory testFactory2 = new TestFactory(); await testFactory.ArrangeAsync(keyType, FileType.Known); await testFactory2.ArrangeAsync(KeyType.Generated, FileType.Known); PGP pgp = new PGP(); // Act await pgp.EncryptFileAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory2.PublicKeyFilePath); var ex = await Assert.ThrowsAsync <PgpException>(async() => await pgp.DecryptFileAndVerifyAsync(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PublicKeyFilePath, testFactory2.PrivateKeyFilePath, testFactory2.Password)); string decryptedContent = await File.ReadAllTextAsync(testFactory.DecryptedContentFilePath); // Assert Assert.Equal("File was not signed.", ex.Message); Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.True(File.Exists(testFactory.DecryptedContentFilePath)); Assert.Equal(string.Empty, decryptedContent.Trim()); // Teardown testFactory.Teardown(); }
public async Task DecryptFileAsync_DecryptEncryptedFileWithDifferentHashAlgorithms(HashAlgorithmTag hashAlgorithmTag) { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(KeyType.Known, FileType.Known); PGP pgp = new PGP(); pgp.HashAlgorithmTag = hashAlgorithmTag; // Act await pgp.EncryptFileAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath); await pgp.DecryptFileAsync(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); string decryptedContent = await File.ReadAllTextAsync(testFactory.DecryptedContentFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.True(File.Exists(testFactory.DecryptedContentFilePath)); Assert.Equal(testFactory.Content, decryptedContent.Trim()); // Teardown testFactory.Teardown(); }
public async Task EncryptFileAsync_CreateEncryptedFileWithMultipleKeys(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); TestFactory testFactory2 = new TestFactory(); await testFactory.ArrangeAsync(keyType, FileType.Known); await testFactory2.ArrangeAsync(KeyType.Generated); PGP pgp = new PGP(); List <string> keys = new List <string>() { testFactory.PublicKeyFilePath, testFactory2.PublicKeyFilePath }; // Act await pgp.EncryptFileAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, keys); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); testFactory2.Teardown(); }
public async Task EncryptFileAsync_CreateEncryptedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(keyType, FileType.Known); PGP pgp = new PGP(); // Act await pgp.EncryptFileAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); }
public async Task EncryptFileAsync_CreateEncryptedFileWithDifferentHashAlgorithms(HashAlgorithmTag hashAlgorithmTag) { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(KeyType.Known, FileType.Known); PGP pgp = new PGP(); pgp.HashAlgorithmTag = hashAlgorithmTag; // Act await pgp.EncryptFileAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); }
public async Task DecryptFileAsync_DecryptEncryptedFileWithMultipleKeys(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); TestFactory testFactory2 = new TestFactory(); await testFactory.ArrangeAsync(keyType, FileType.Known); await testFactory2.ArrangeAsync(KeyType.Generated, FileType.Known); PGP pgp = new PGP(); List <string> keys = new List <string>() { testFactory.PublicKeyFilePath, testFactory2.PublicKeyFilePath }; // Act await pgp.EncryptFileAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, keys); await pgp.DecryptFileAsync(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); await pgp.DecryptFileAsync(testFactory.EncryptedContentFilePath, testFactory2.DecryptedContentFilePath, testFactory2.PrivateKeyFilePath, testFactory2.Password); string decryptedContent1 = await File.ReadAllTextAsync(testFactory.DecryptedContentFilePath); string decryptedContent2 = await File.ReadAllTextAsync(testFactory2.DecryptedContentFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.True(File.Exists(testFactory.DecryptedContentFilePath)); Assert.True(File.Exists(testFactory2.DecryptedContentFilePath)); Assert.Equal(testFactory.Content, decryptedContent1.Trim()); Assert.Equal(testFactory.Content, decryptedContent2.Trim()); // Teardown testFactory.Teardown(); }