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> Sign the given <paramref name="payload"/> with the given <paramref name="privateKey"/>. </summary> /// <param name="payload"> Payload to sign </param> /// <param name="privateKey"> Key to use </param> /// <returns> Signed string </returns> public static string Sign(string payload, string privateKey, string password = "******") { MemoryStream ins = new MemoryStream(payload.ToBytesUTF8()); MemoryStream outs = new MemoryStream(); MemoryStream keys = new MemoryStream(privateKey.ToBytesUTF8()); DateTime start = DateTime.UtcNow; instance.SignStream(ins, outs, keys, password, true, true); DateTime end = DateTime.UtcNow; Log.Debug($"Pgp.Sign took {(end - start).TotalMilliseconds}ms"); return(Encoding.UTF8.GetString(outs.ToArray()).Replace("\r\n", "\n")); }
public void SignStream_CreateSignedFile(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 privateKeyStream = new FileStream(testFactory.PrivateKeyFilePath, FileMode.Open, FileAccess.Read)) pgp.SignStream(inputFileStream, outputFileStream, privateKeyStream, testFactory.Password); // Assert Assert.True(File.Exists(testFactory.EncryptedContentFilePath)); // Teardown testFactory.Teardown(); }