Skip to content

How to pass certificate password to config-crypter encrypt/decrypt commands? #1

@Hussein-Dahir

Description

@Hussein-Dahir

Hi,

I created an SSL certificate with an export password, and I noticed that I can provide this password in my .NET code using crypter.CertificateLoader option of ConfigureAppConfiguration, this way:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .UseStartup<Startup>()
        .ConfigureAppConfiguration(cfg =>
        {
            cfg.AddEncryptedAppSettings(crypter =>
            {
                crypter.KeysToDecrypt = new List<string> { "ConnectionStrings:DefaultConnection" };
                crypter.CertificateLoader = new MyCertificateLoader();
            });
        });


public class MyCertificateLoader : ICertificateLoader
{
    public X509Certificate2 LoadCertificate()
    {
        return new X509Certificate2("mycert.pfx", "mypassword", X509KeyStorageFlags.MachineKeySet);
    }
}

But I could not find any way to provide this password to the command I use in the cmd!

config-crypter encrypt -p mycert.pfx -f appsettings.json -k "ConnectionStrings.DefaultConnection" 
config-crypter decrypt-p mycert.pfx -f appsettings.json -k "ConnectionStrings.DefaultConnection" 

Is there a way to do so?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions