public async Task EncryptStreamAndSignAsync_CreateEncryptedAndSignedStreamWithMultipleKeys(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 using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.EncryptedContentFilePath)) using (Stream publicKeyStream1 = new FileStream(testFactory.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) using (Stream publicKeyStream2 = new FileStream(testFactory2.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) await pgp.EncryptStreamAndSignAsync(inputFileStream, outputFileStream, new List <Stream>() { publicKeyStream1, publicKeyStream2 }, privateKeyStream, testFactory.Password); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); }
public void EncryptFile_CreateEncryptedFileWithMultipleKeys(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); TestFactory testFactory2 = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); testFactory2.Arrange(KeyType.Generated); PGP pgp = new PGP(); List <string> keys = new List <string>() { testFactory.PublicKeyFilePath, testFactory2.PublicKeyFilePath }; // Act pgp.EncryptFile(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, keys); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); testFactory2.Teardown(); }
public async Task DecryptStreamAsync_DecryptSignedAndEncryptedStream(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(keyType, FileType.Known); PGP pgp = new PGP(); // Act using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.EncryptedContentFilePath)) using (Stream publicKeyStream = new FileStream(testFactory.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) await pgp.EncryptStreamAndSignAsync(inputFileStream, outputFileStream, publicKeyStream, privateKeyStream, testFactory.Password); using (FileStream inputFileStream = new FileStream(testFactory.EncryptedContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.DecryptedContentFilePath)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) await pgp.DecryptStreamAsync(inputFileStream, outputFileStream, privateKeyStream, testFactory.Password); string decryptedContent = await File.ReadAllTextAsync(testFactory.DecryptedContentFilePath); bool verified = pgp.VerifyFile(testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.True(File.Exists(testFactory.DecryptedContentFilePath)); Assert.Equal(testFactory.Content, decryptedContent.Trim()); Assert.True(verified); // Teardown testFactory.Teardown(); }
public async Task DecryptFileAndVerifyAsync_DecryptSignedAndEncryptedFileDifferentKeys(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.EncryptFileAndSignAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory2.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); await pgp.DecryptFileAndVerifyAsync(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PublicKeyFilePath, testFactory2.PrivateKeyFilePath, testFactory2.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 VerifyAsync_DoNotVerifySignedStream(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(); bool verified = false; // Act using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.SignedContentFilePath)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) await pgp.SignStreamAsync(inputFileStream, outputFileStream, privateKeyStream, testFactory.Password); using (FileStream inputFileStream = new FileStream(testFactory.SignedContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream publicKeyStream = new FileStream(testFactory2.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) verified = await pgp.VerifyStreamAsync(inputFileStream, publicKeyStream); // Assert Assert.True(File.Exists(testFactory.SignedContentFilePath)); Assert.False(verified); // Teardown testFactory.Teardown(); }
public void Verify_DoNotVerifyEncryptedAndSignedStream(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 using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.EncryptedContentFilePath)) using (Stream publicKeyStream = new FileStream(testFactory.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.EncryptStreamAndSign(inputFileStream, outputFileStream, publicKeyStream, privateKeyStream, testFactory.Password); bool verified = pgp.VerifyFile(testFactory.EncryptedContentFilePath, testFactory2.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.False(verified); // Teardown testFactory.Teardown(); }
public void Verify_VerifySignedStream(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); PGP pgp = new PGP(); bool verified = false; // Act using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.SignedContentFilePath)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.SignStream(inputFileStream, outputFileStream, privateKeyStream, testFactory.Password); using (FileStream inputFileStream = new FileStream(testFactory.SignedContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream publicKeyStream = new FileStream(testFactory.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) verified = pgp.VerifyStream(inputFileStream, publicKeyStream); // Assert Assert.True(File.Exists(testFactory.SignedContentFilePath)); Assert.True(verified); // Teardown testFactory.Teardown(); }
public void DecryptStream_DecryptEncryptedStream(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); PGP pgp = new PGP(); // Act using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.EncryptedContentFilePath)) using (Stream publicKeyStream = new FileStream(testFactory.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.EncryptStream(inputFileStream, outputFileStream, publicKeyStream); using (FileStream inputFileStream = new FileStream(testFactory.EncryptedContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.DecryptedContentFilePath)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.DecryptStream(inputFileStream, outputFileStream, privateKeyStream, 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(); }
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 void EncryptStream_CreateEncryptedStreamWithMultipleKeys(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 using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.EncryptedContentFilePath)) using (Stream publicKeyStream1 = new FileStream(testFactory.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) using (Stream publicKeyStream2 = new FileStream(testFactory2.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.EncryptStream(inputFileStream, outputFileStream, new List <Stream>() { publicKeyStream1, publicKeyStream2 }); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); }
public async Task DecryptFileAndVerifyAsync_DecryptWithWrongKey(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.EncryptFileAndSignAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); var ex = await Assert.ThrowsAsync <PgpException>(async() => await pgp.DecryptFileAndVerifyAsync(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory2.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password)); string decryptedContent = await File.ReadAllTextAsync(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(); }
public async Task EncryptFileAndSignAsync_CreateEncryptedAndSignedFileWithMultipleKeys(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.EncryptFileAndSignAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, keys, testFactory.PrivateKeyFilePath, testFactory.Password); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); testFactory2.Teardown(); }
public void DecryptFileAndVerify_DecryptUnsignedFile(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.EncryptFile(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory2.PublicKeyFilePath); var ex = Assert.Throws <PgpException>(() => pgp.DecryptFileAndVerify(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PublicKeyFilePath, testFactory2.PrivateKeyFilePath, testFactory2.Password)); string decryptedContent = File.ReadAllText(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 void DecryptFile_DecryptSignedAndEncryptedFileWithMultipleKeys(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(); List <string> keys = new List <string>() { testFactory.PublicKeyFilePath, testFactory2.PublicKeyFilePath }; // Act pgp.EncryptFileAndSign(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, keys, testFactory.PrivateKeyFilePath, testFactory.Password); pgp.DecryptFile(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); pgp.DecryptFile(testFactory.EncryptedContentFilePath, testFactory2.DecryptedContentFilePath, testFactory2.PrivateKeyFilePath, testFactory2.Password); string decryptedContent1 = File.ReadAllText(testFactory.DecryptedContentFilePath); string decryptedContent2 = File.ReadAllText(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(); }
public void DecryptStream_DecryptSignedAndEncryptedStreamWithMultipleKeys(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 using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.EncryptedContentFilePath)) using (Stream publicKeyStream1 = new FileStream(testFactory.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) using (Stream publicKeyStream2 = new FileStream(testFactory2.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.EncryptStream(inputFileStream, outputFileStream, new List <Stream>() { publicKeyStream1, publicKeyStream2 }); using (FileStream inputFileStream = new FileStream(testFactory.EncryptedContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.DecryptedContentFilePath)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.DecryptStream(inputFileStream, outputFileStream, privateKeyStream, testFactory.Password); using (FileStream inputFileStream = new FileStream(testFactory.EncryptedContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory2.DecryptedContentFilePath)) using (Stream privateKeyStream = new FileStream(testFactory2.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.DecryptStream(inputFileStream, outputFileStream, privateKeyStream, testFactory2.Password); string decryptedContent1 = File.ReadAllText(testFactory.DecryptedContentFilePath); string decryptedContent2 = File.ReadAllText(testFactory2.DecryptedContentFilePath); bool verified = pgp.VerifyFile(testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath); // 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()); Assert.True(verified); // Teardown testFactory.Teardown(); }
public async Task ClearSignAndVerifyFileAsync_CreateClearSignedFileAndVerify(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(keyType, FileType.Known); PGP pgp = new PGP(); // Act await pgp.ClearSignFileAsync(testFactory.ContentFilePath, testFactory.SignedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); // Assert Assert.True(await pgp.VerifyClearFileAsync(testFactory.SignedContentFilePath, testFactory.PublicKeyFilePath)); // Teardown testFactory.Teardown(); }
public void EncryptFile_CreateEncryptedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); PGP pgp = new PGP(); // Act pgp.EncryptFile(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); }
public async Task SignFileAsync_CreateSignedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(keyType, FileType.Known); PGP pgp = new PGP(); // Act await pgp.SignFileAsync(testFactory.ContentFilePath, testFactory.SignedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); // Assert Assert.True(File.Exists(testFactory.SignedContentFilePath)); // Teardown testFactory.Teardown(); }
public void ClearSignFile_CreateClearSignedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); PGP pgp = new PGP(); // Act pgp.ClearSignFile(testFactory.ContentFilePath, testFactory.SignedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); // Assert Assert.True(File.Exists(testFactory.SignedContentFilePath)); // Teardown testFactory.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 void GenerateKey_CreatePublicPrivateKeyFiles() { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(); PGP pgp = new PGP(); // Act pgp.GenerateKey(testFactory.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); // Assert Assert.True(File.Exists(testFactory.PublicKeyFilePath)); Assert.True(File.Exists(testFactory.PrivateKeyFilePath)); // Cleanup testFactory.Teardown(); }
public async Task GenerateKeyAsync_CreatePublicPrivateKeyFiles() { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(); PGP pgp = new PGP(); // Act await pgp.GenerateKeyAsync(testFactory.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); // Assert Assert.True(File.Exists(testFactory.PublicKeyFilePath)); Assert.True(File.Exists(testFactory.PrivateKeyFilePath)); // Cleanup 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 void Verify_VerifySignedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); PGP pgp = new PGP(); // Act pgp.SignFile(testFactory.ContentFilePath, testFactory.SignedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); bool verified = pgp.VerifyFile(testFactory.SignedContentFilePath, testFactory.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.SignedContentFilePath)); Assert.True(verified); // Teardown testFactory.Teardown(); }
public async Task DecryptStreamAsync_DecryptEncryptedStreamWithMultipleKeys(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 using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.EncryptedContentFilePath)) using (Stream publicKeyStream1 = new FileStream(testFactory.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) using (Stream publicKeyStream2 = new FileStream(testFactory2.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) await pgp.EncryptStreamAsync(inputFileStream, outputFileStream, new List <Stream>() { publicKeyStream1, publicKeyStream2 }); using (FileStream inputFileStream = new FileStream(testFactory.EncryptedContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.DecryptedContentFilePath)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) await pgp.DecryptStreamAsync(inputFileStream, outputFileStream, privateKeyStream, testFactory.Password); using (FileStream inputFileStream = new FileStream(testFactory.EncryptedContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory2.DecryptedContentFilePath)) using (Stream privateKeyStream = new FileStream(testFactory2.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) await pgp.DecryptStreamAsync(inputFileStream, outputFileStream, privateKeyStream, 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(); }
public void ClearSignAndDoNotVerifyFile_CreateClearSignedFileAndDoNotVerify(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); TestFactory testFactory2 = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); testFactory2.Arrange(KeyType.Generated); PGP pgp = new PGP(); // Act pgp.ClearSignFile(testFactory.ContentFilePath, testFactory.SignedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); // Assert Assert.False(pgp.VerifyClearFile(testFactory.SignedContentFilePath, testFactory2.PublicKeyFilePath)); // Teardown testFactory.Teardown(); testFactory2.Teardown(); }
public async Task SignStreamAsync_CreateSignedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(keyType, FileType.Known); PGP pgp = new PGP(); // Act using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.EncryptedContentFilePath)) using (Stream privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) await pgp.SignStreamAsync(inputFileStream, outputFileStream, privateKeyStream, testFactory.Password); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); }
public async Task VerifyAsync_VerifyEncryptedAndSignedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); await testFactory.ArrangeAsync(keyType, FileType.Known); PGP pgp = new PGP(); // Act await pgp.EncryptFileAndSignAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); bool verified = await pgp.VerifyFileAsync(testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.True(verified); // Teardown testFactory.Teardown(); }
public void EncryptStream_CreateEncryptedFile(KeyType keyType) { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(keyType, FileType.Known); PGP pgp = new PGP(); // Act using (FileStream inputFileStream = new FileStream(testFactory.ContentFilePath, FileMode.Open, FileAccess.Read)) using (Stream outputFileStream = File.Create(testFactory.EncryptedContentFilePath)) using (Stream publicKeyStream = new FileStream(testFactory.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.EncryptStream(inputFileStream, outputFileStream, publicKeyStream); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); }
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(); }