PgpCore icon indicating copy to clipboard operation
PgpCore copied to clipboard

Passing multiple newlines causes Verfication error in VerifyClearAsync

Open OfficialPixelBrush opened this issue 1 year ago • 1 comments

Passing a string such as foo\nbar\n\n or foo\n\nbar into ClearSignAsync and then the output of this into VerifyClearAsync returns a false. This is true for any consecutive newlines.

Example:

string message = "foo\nbar\n\n";

// Generate keys
using (PGP pgp = new PGP())
{
    pgp.GenerateKey(new FileInfo("public.asc"), new FileInfo("private.asc"), "[email protected]", "insecure_password");
}

// Sign the Message
string privateKey = File.ReadAllText("private.asc");
EncryptionKeys encryptionKeys = new EncryptionKeys(privateKey, password);

PGP pgp2 = new PGP(encryptionKeys);
string signedMessage = await pgp2.ClearSignAsync(message);

// Vertify the Signed Message
string publicKey = File.ReadAllText("public.asc");
EncryptionKeys encryptionKeys = new EncryptionKeys(publicKey);

PGP pgp3 = new PGP(encryptionKeys);
bool isVerified = await pgp3.VerifyClearAsync(signedMessage);

// This will return "false"
Console.WriteLine(isVerified);

Removing the newlines is a potential workaround, albeit a suboptimal one, since some may need these characters.

message = message.Replace("\n", "").Replace("\r", "");

OfficialPixelBrush avatar Feb 05 '25 11:02 OfficialPixelBrush

Interesting, thanks for pointing this out, I haven't seen this before.

It's going to be a little while until I get a chance to look into it so I'd suggest just replacing them for now and then I'll push out a fix when I get a chance.

mattosaurus avatar Feb 05 '25 11:02 mattosaurus