mattosaurus / PgpCore

.NET Core class library for using PGP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Could not find any signing keys in keyring

Phoenix01001010 opened this issue · comments

Hello, I have used the Pgpcore 6.3.1 library in my project to sign and encrypt a string. The code works fine locally, but when deployed as a web app on Azure, I am encountering an error: "Could not find any signing keys in the keyring." I have been reading the keys from the appsettings file for now and passing them as a string (I also tried using a memory stream), but none of these methods are working. Could someone please help me identify the possible root cause?

string? publicKey = Helper.GetAppSettings("KeyConfig:PublicKey");
string? privateKey = Helper.GetAppSettings("KeyConfig:PrivateKey");
EncryptionKeys signingKey = new(publicKey, privateKey, passphrase); -Error line

Hi, the issue is likely because the path to your appsettings file will be different on your local machine than in Azure so you won't be loading any values in Azure.

I'd suggest using the inbuilt configuration provider rather than a custom helper class and making it available via DI.

        public static IConfiguration Configuration { get; } = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .AddEnvironmentVariables()
            .Build();

Hello @mattosaurus Thank you for your speedy response. I can confirm that it's not an issue with values not being loaded in Azure. With additional logging, I could confirm this.

Full stack trace:

Error: Encryption failed. [Could not find any signing keys in keyring at PgpCore.Utilities.FindBestSigningKey(PgpSecretKeyRingBundle secretKeyRingBundle)
at PgpCore.EncryptionKeys.<>c__DisplayClass48_0.b__8()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at System.Lazy1.get_Value()
at PgpCore.EncryptionKeys.get_SigningSecretKey()
at PgpCore.EncryptionKeys.InitializeKeys(IEnumerable`1 publicKeyRings)
at PgpCore.EncryptionKeys..ctor(String publicKey, String privateKey, String passPhrase)