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 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 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 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 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 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(); }
public void Verify_DoNotVerifyEncryptedAndSignedFile(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); bool verified = pgp.VerifyFile(testFactory.EncryptedContentFilePath, testFactory2.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.False(verified); // Teardown testFactory.Teardown(); }
public async Task VerifyAsync_DoNotVerifySignedFile(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.SignFileAsync(testFactory.ContentFilePath, testFactory.SignedContentFilePath, testFactory.PrivateKeyFilePath, testFactory.Password); bool verified = await pgp.VerifyFileAsync(testFactory.SignedContentFilePath, testFactory2.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.SignedContentFilePath)); Assert.False(verified); // Teardown testFactory.Teardown(); }
public void DecryptFile_DecryptEncryptedFileWithDifferentHashAlgorithms(HashAlgorithmTag hashAlgorithmTag) { // Arrange TestFactory testFactory = new TestFactory(); testFactory.Arrange(KeyType.Known, FileType.Known); PGP pgp = new PGP(); pgp.HashAlgorithmTag = hashAlgorithmTag; // Act pgp.EncryptFile(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath); pgp.DecryptFile(testFactory.EncryptedContentFilePath, testFactory.DecryptedContentFilePath, 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(); }
public async Task DecryptFileAsync_DecryptSignedAndEncryptedFile(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, armor : false); 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 DecryptFileAsync_DecryptSignedAndEncryptedFileWithMultipleKeys(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.EncryptFileAndSignAsync(testFactory.ContentFilePath, testFactory.EncryptedContentFilePath, keys, testFactory.PrivateKeyFilePath, testFactory.Password); 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(); }
public async Task VerifyAsync_VerifyEncryptedAndSignedStream(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); bool verified = await pgp.VerifyFileAsync(testFactory.EncryptedContentFilePath, testFactory.PublicKeyFilePath); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); Assert.True(verified); // Teardown testFactory.Teardown(); }
public async Task EncryptStreamAsync_CreateEncryptedStreamWithMultipleKeys(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 }); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); }