public void Verify_DoNotVerifySignedStream(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(); 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(testFactory2.PublicKeyFilePath, FileMode.Open, FileAccess.Read)) verified = pgp.VerifyStream(inputFileStream, publicKeyStream); // Assert Assert.True(File.Exists(testFactory.SignedContentFilePath)); Assert.False(verified); // Teardown testFactory.Teardown(); }
/// <summary> Verify the given <paramref name="encrypted"/> payload was signed with private key that matches <paramref name="publicKey"/></summary> /// <param name="encrypted"> Encrypted payload to verify </param> /// <param name="publicKey"> Public key to verify with </param> /// <returns> True, if verified, or false if not. </returns> public static bool Verify(string encrypted, string publicKey) { MemoryStream ins = new MemoryStream(encrypted.ToBytesUTF8()); MemoryStream keys = new MemoryStream(publicKey.ToBytesUTF8()); return(instance.VerifyStream(ins, keys)); }