C#


CSHARP.HARDCODED.KEY : Hardcoded Cryptographic Key (C#)

要旨

A hardcoded cryptographic key is used.

プロパティ

クラス名 Hardcoded Cryptographic Key (C#)
日本語クラス名 Hardcoded Cryptographic Key (C#)
クラス分類 セキュリティ (security)
ニーモニック CSHARP.HARDCODED.KEY
カテゴリー
CWE CWE:321 Use of Hard-coded Cryptographic Key
対応言語 C# で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Hardcoded Cryptographic Key (C#)"

using System;
using System.Security.Cryptography;
using System.Text;
using System.IO;

namespace Hard_Coded_Cryptographic_Key {

    class Hard_Coded_Cryptographic_Key {

        public void MyMethod() {
            string data = "568f{_62@!a";
            string stringToEncrypt = "My secret";
            byte[] byteCipherText = null;
        
            using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider()) {
                ICryptoTransform encryptor = aes.CreateEncryptor(Encoding.UTF8.GetBytes(data), aes.IV);  // 'Hardcoded Cryptographic Key (C#)' warning issued here
                // ...
            }
        }
    }
}

解決法

Avoid hardcoded keys: use a secure key generator instead.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。