0

私が使用しているライブラリの 1 つでは、使用時にアカウント用に一意に生成された API キーを渡す必要があり、完全に非公開で安全でなければなりません。

キーをアプリケーションに入れると、private const string API_KEY = "ABC";誰かがコードを逆コンパイルしてキーを表示できる可能性があります。

一般的な .NET 難読化 (無料の難読化ツールなどによる) でこれを隠すことができますか? それとも、スヌーパーが元の API キーを取得するのを阻止するためのより良い方法はありますか?

4

1 に答える 1

1

app.configファイル内のカスタムセクションを使用できます(適切な代替手段)。データ(キー)を入力してから、構成ファイルを暗号化します。サンプルは次のとおりです。

            //loading config file...
            config = ConfigurationManager.OpenExeConfiguration("AvtoNetPublisher.exe");
            //getting specific section (in this case custom class)
            csp = (GmailSettingsProvider)config.GetSection("gsp");
            if (!csp.SectionInformation.IsProtected)
            {
                DialogResult result = MessageBox.Show("Configuration is not protected, proceed to enter configuration!", "Configuration is not protected", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result != DialogResult.OK)
                {
                    throw new Exception("Configuration was interupted by user!");
                }
                csp.UserName = Microsoft.VisualBasic.Interaction.InputBox("Enter user name", "UserName", csp.UserName, Cursor.Position.X, Cursor.Position.Y);
                csp.Password = Microsoft.VisualBasic.Interaction.InputBox("Enter password", "Password", csp.Password, Cursor.Position.X, Cursor.Position.Y);
                csp.ImapServer = Microsoft.VisualBasic.Interaction.InputBox("Enter ImapServer", "ImapServer", csp.ImapServer, Cursor.Position.X, Cursor.Position.Y);
                csp.Port = Convert.ToInt16(Microsoft.VisualBasic.Interaction.InputBox("Enter int32 Port", "Port", csp.Port.ToString(), Cursor.Position.X, Cursor.Position.Y));
                csp.EnableSSL = Convert.ToBoolean(Microsoft.VisualBasic.Interaction.InputBox("Enter bool EnableSSL", "EnableSSL", csp.EnableSSL.ToString(), Cursor.Position.X, Cursor.Position.Y));
                csp.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
                config.Save();
            }

これは、アプリの最初のインストールまたはロード時にトリガーできます。

于 2012-09-19T09:17:26.823 に答える