1

サードパーティのAPIを使用する.NETアプリケーションを作成しています。APIクレデンシャルを保存するための最良の方法は何ですか?RSACryptoServiceProviderを使用して暗号化することを考えていますが、質問は次のとおりです。RSAを使用して資格情報を暗号化する場合、資格情報を復号化するためにアプリケーションのどこかに秘密鍵が必要です。基本的に無関係ですか?誰でも先に進んで暗号化されたクレデンシャルを取得し、クレデンシャルを復号化するために提供する必要のあるキーを使用できるためです。

秘密鍵を処理し、私のアプリケーションを使用する人から遠ざけるための最良の方法は何ですか?

クラスのどこかに文字列として保存すると、キーを読み取ることができますか?

4

2 に答える 2

1

はい、単純な文字列として保存すれば、キーを読み取ることができます。ただし、SecureStringクラスを使用して、揮発性アクセスを最小限に抑えることができます。

また、SecureStringの内容を文字列に入れないでください。入れた場合、文字列はヒープ内で暗号化されずに存続し、ガベージコレクション後にメモリが再利用されるまで文字がゼロになりません。

C#経由のCLRからの例:

public static class Program
{
    public static void Main()
    {
        using (SecureString ss = new SecureString())
        {
            Console.Write("Please enter password: ");
            while (true)
            {
                ConsoleKeyInfo cki = Console.ReadKey(true);
                if (cki.Key == ConsoleKey.Enter) break;
                // Append password characters into the SecureString
                ss.AppendChar(cki.KeyChar);
                Console.Write("*");
            }
            Console.WriteLine();
            // Password entered, display it for demonstration purposes
            DisplaySecureString(ss);
        }
        // After 'using', the SecureString is Disposed; no sensitive data in memory
    }
    // This method is unsafe because it accesses unmanaged memory
    private unsafe static void DisplaySecureString(SecureString ss)
    {
        Char* pc = null;
        try
        {
            // Decrypt the SecureString into an unmanaged memory buffer
            pc = (Char*)Marshal.SecureStringToCoTaskMemUnicode(ss);
            // Access the unmanaged memory buffer that
            // contains the decrypted SecureString
            for (Int32 index = 0; pc[index] != 0; index++)
                Console.Write(pc[index]);
        }
        finally
        {
            // Make sure we zero and free the unmanaged memory buffer that contains
            // the decrypted SecureString characters
            if (pc != null)
                Marshal.ZeroFreeCoTaskMemUnicode((IntPtr)pc);
        }
    }
}
于 2012-08-23T13:27:56.017 に答える
1

すでにマシンとWindowsのユーザー名とパスワードにアクセスしている断固とした攻撃者からそれを隠すことはできません。

そうは言っても、ProtectedDataクラスは、適切な資格情報を持たないユーザーがデータにアクセスできないようにするための最も簡単な方法です。

于 2012-08-23T13:42:20.280 に答える