Open Closed

Encrypted Setting Default Value #5911


User avatar
0
douglasmolon@gmail.com created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, and please first use the search on the homepage. Provide us with the following info:

  • ABP Framework version: v7.3.3
  • UI Type: Angular
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace: below
  • Steps to reproduce the issue: below

Hello! We are using the ABP settings provider, but we are having difficulty setting a default value for a encrypted setting. We can set the default value, but it cannot be read after. I guess it's because ABP is trying to decrypt a value that is not encrypted yet. Is there a way to set a default value to an encrypted setting?

Thanks.


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    We can set the default value

    Please share your code. Usually, you don't need to care about the encryption, which is done automatically.

    https://docs.abp.io/en/abp/latest/Settings#isettingencryptionservice

  • User Avatar
    0
    douglasmolon@gmail.com created

    hi

    We can set the default value

    Please share your code.Usually, you don't need to care about the encryption, which is done automatically.

    https://docs.abp.io/en/abp/latest/Settings#isettingencryptionservice

     public override void Define(ISettingDefinitionContext context)
        {
            context.Add(new SettingDefinition(ProductServiceSettings.DataShareApiUrl, "http://192.168.15.3:5150", isEncrypted: false));
            context.Add(new SettingDefinition(ProductServiceSettings.DataSharePublicKey, "015e5387-05d4-4904-9d1a-b7a6c4241bd6", isEncrypted: false));
            context.Add(new SettingDefinition(ProductServiceSettings.DataShareSecretKey, "11ddf380-c141-4889-b5ee-dcdd72c0b8d0", isEncrypted: true));
            context.Add(new SettingDefinition(ProductServiceSettings.SchedulerUsername, "scheduler_user"));
            context.Add(new SettingDefinition(ProductServiceSettings.SchedulerPassword, "123456", isEncrypted: true));
           // and so on...
        }
    

    Please note that settings that are not encrypted we can get default values using ISettingProvider normally, like this example: var urlHeader = $"{(await settingProvider.GetOrNullAsync(ProductServiceSettings.DataShareApiUrl)).EnsureEndsWith('/')}{url}";

    But encrypted ones returns null. like this one: await settingProvider.GetOrNullAsync(ProductServiceSettings.DataShareSecretKey)

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try to inject the ISettingEncryptionService and Encrypt your default value?

  • User Avatar
    0
    douglasmolon@gmail.com created

    hi

    Can you try to inject the ISettingEncryptionService and Encrypt your default value?

    I tested it with IStringEncryptionService directly and it worked!

    The ISettingEncryptionService Encrypt method needs a SettingDefinition type parameter but doesn't really use it. Maybe this was unintentional.

    Thank you!

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15