【问题标题】:What is the Encryption method use in DpapiProtectedConfigurationProvider?DpapiProtectedConfigurationProvider 中使用的加密方法是什么?
【发布时间】:2022-01-13 12:36:53
【问题描述】:

我想使用 DpapiProtectedConfigurationProvider 生成密码文本。 我在互联网上看到的所有代码都是在 app.config 中执行的。我知道这是最初构建的原因。但我有不同的用法。我有界面,用户必须在文本框中输入文本,然后单击按钮,我需要使用 DpapiProtectedConfigurationProvider 生成 cpher 文本。如何做到这一点?

目前我正在使用以下代码在 app.config 中生成它。但这不是我想要的

  Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        //Configuration config = ConfigurationManager.OpenExeConfiguration(exefilePath);

        ConfigurationSection section = config.GetSection(sectionKey);

        if (section != null)
        {
            if (section.ElementInformation.IsLocked)
            {
                Console.WriteLine("Section: {0} is locked", sectionKey);
            }
            else
            {
                if (!section.SectionInformation.IsProtected)
                {
                    //%windir%\system32\Microsoft\Protect\S-1-5-18
                    section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                    section.SectionInformation.ForceSave = true;
                    Console.WriteLine("Encrypting: {0} {1}", section.SectionInformation.Name, section.SectionInformation.SectionName);

                }
                else
                { // display values for current config application name value pairs
                   
                    //
                    section.SectionInformation.UnprotectSection();
                    section.SectionInformation.ForceSave = true;
                    Console.WriteLine("Decrypting: {0} {1}", section.SectionInformation.Name, section.SectionInformation.SectionName);
                }
            }
        }
        else
        {
            Console.WriteLine("Section: {0} is null", sectionKey);
        }

        //
        config.Save(ConfigurationSaveMode.Full);
        Console.WriteLine("Saving file: {0}", config.FilePath);

我该怎么做?

【问题讨论】:

    标签: c# encryption


    【解决方案1】:

    The DpapiProtectedConfigurationProvider class “使用 Windows 内置加密服务,可以配置为针对特定机器或特定于用户帐户的保护。”

    根据使用的标志,使用 DPAPI 加密的数据只能通过运行在加密的同一台机器上的代码或运行在加密的同一用户帐户下的代码来解密。

    所使用的精确算法可能因所使用的 Windows 版本而异。据我所知,the CryptProtectData function 使用 3DES 或 AES256:

    c# - Which encryption algorithm does the ProtectData class use? - Stack Overflow
    c# - Which Encryption algorithm does ProtectedData use? - Stack Overflow

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-21
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      • 2011-06-29
      • 1970-01-01
      • 2023-04-02
      相关资源
      最近更新 更多