mattosaurus / PgpCore

.NET Core class library for using PGP
MIT License
245 stars 98 forks source link

"Can't find encryption key in key ring." #133

Closed felix-exon closed 3 years ago

felix-exon commented 3 years ago
Utilities.ReadPublicKey(pkFileName) //throws "Can't find encryption key in key ring."
Utilities.ReadPublicKey(pkFileStream) //does work without any problem

I am using version 5.3.1.

To my understanding ReadPublicKey(string file) should just be a wrapper and open a stream itself.

mattosaurus commented 3 years ago

Hi, it's actually expecting the string value provided to be the key itself, not the path to it. This then gets converted to a stream.

        public static PgpPublicKey ReadPublicKey(string publicKey)
        {

            if (string.IsNullOrEmpty(publicKey))
                throw new FileNotFoundException(String.Format("Public key was not provided"));

            return ReadPublicKey(publicKey.GetStream());
        }
felix-exon commented 3 years ago

Wow this makes perfect sense. For some reason I expected it to be the path to the file. I am pretty sure this worked before.

mattosaurus commented 3 years ago

It probably did, things have changed behind the scenes a bit. If you want to use the path you can pass it a FileInfo object.

Most methods should now accept a stream, a string or a FileInfo. This was done so raw values could be passed in via string.

felix-exon commented 3 years ago

I totally get that. I was just surprised it stopped working. It's not a big deal to wrap it in a FileStream or FileInfo. Would be super nice, if the method hat some decorators.

/// <summary>
/// 
/// </summary>
/// <param name="publicKey">The raw string of the key-files content itself</param>
/// <returns></returns>

That way pressing F12 in VS would instantly reveal the problem.

Would be also nice to check if a FileInfo or Stream could be opened. If so just recursively call the method. That way it's convenient and does not break existing applications - OR - check if it's a filepath and throw an exception accordingly

Right now this could be a bit misleading imo

mattosaurus commented 3 years ago

Good point, additional decorations would certainly be useful.

mattosaurus commented 3 years ago

Commented these specific methods in v5.3.2