3

同様の質問があります 対称アルゴリズムでキーを管理する方法 SHA-1ハッシュで使用する秘密キーをどこに保存しますか?

私の質問は同じですが、別の方法で質問したいと思います

私はC#アプリケーションを持っています。アプリケーションでいくつかのデータを暗号化しています。暗号化には秘密鍵またはパスワードを使用しています。これと同じことが復号化にも必要です。

この秘密鍵またはパスワードをアプリケーションのどこに/どのように保存しますか?反射から文字列パスワードを表示するのは簡単です。私はパスワードを生成するためにいくつかの組み合わせを使用するかもしれませんが、一部の賢い人はいくつかの努力でそれを推測することができます。

データを暗号化するためにアプリケーションで使用される秘密のパスワードを保存または管理するための安全な方法はありますか?

4

2 に答える 2

7

キーを安全に保管する方法が保証されているとは思えません。最終的に、プログラムはキーにアクセスする必要があり、クラッカーはリバースエンジニアリングを介してそれがどのように発生しているかを簡単に把握し、その文字列を必要な場所にリダイレクトできます。

最善のオプションは次のとおりです。

  • キーを可能な限り難読化します。これにより、「秘密鍵」へのアクセスがより困難になりますが、不可能になることはありません(上記を参照)。文字列として保存するのではなく、関数を使用して生成するか、シードを使用して関数に渡し、秘密の文字列を取得します。

  • ユースケースで許可されている場合は、公開鍵と秘密鍵のペアを使用してください。これは、アプリケーションでデータを暗号化し、サーバーに送信してから、復号化する場合にのみ機能します。この場合、公開鍵をアプリケーションに埋め込み(クラッカーがそれを発見したかどうかは関係ありません)、秘密鍵を自分自身またはサーバーに保持します。

于 2012-11-27T07:36:17.563 に答える
0

キーをアプリ設定として保存し、アプリ設定を暗号化すると、かなり節約できると思います。

次のコードを使用して、app.configのセクションを暗号化できます。

using System;
using System.Configuration;

public static class ConfigurationEncryptor {
    [Flags]
    public enum ConfigurationSectionType {
        ConnectionStrings = 1,
        ApplicationSettings = 2
    }

    /// <summary>
    /// Encrypts the given sections in the current configuration.
    /// </summary>
    /// <returns>True is the configuration file was encrypted</returns>
    public static bool Encrypt(ConfigurationSectionType section) {
        bool result = false;

        Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        if (config == null)
            throw new Exception("Cannot open the configuration file.");

        if (section.HasFlag(ConfigurationSectionType.ConnectionStrings)) {
            result = result || EncryptSection(config, "connectionStrings");
        }

        if (section.HasFlag(ConfigurationSectionType.ApplicationSettings)) {
            result = result || EncryptSection(config, "appSettings");
        }

        return result;
    }

    /// <summary>
    /// Encrypts the specified section.
    /// </summary>
    /// <param name="config">The config.</param>
    /// <param name="section">The section.</param>
    private static bool EncryptSection(Configuration config, string section) {
        ConfigurationSection currentSection = config.GetSection(section);
        if (currentSection == null)
            throw new Exception("Cannot find " + section + " section in configuration file.");
        if (!currentSection.SectionInformation.IsProtected) {
            currentSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
            config.Save();

            // Refresh configuration
            ConfigurationManager.RefreshSection(section);

            return true;
        }
        return false;
    }
}

そして、次のように使用します(たとえば、Main()メソッドで):

ConfigurationEncryptor.Encrypt(
    ConfigurationEncryptor.ConfigurationSectionType.ApplicationSettings |
    ConfigurationEncryptor.ConfigurationSectionType.ConnectionStrings
);
于 2012-11-27T07:36:36.250 に答える