英語で読む

次の方法で共有


KeySizes クラス

定義

対称暗号化アルゴリズムの有効なキー サイズのセットを定義します。

C#
public sealed class KeySizes
C#
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class KeySizes
継承
KeySizes
属性

次の例は、 クラスのメンバーの使用を KeySizes 示しています。

C#
using System;
using System.Security.Cryptography;

namespace Contoso
{
    class KeySizesMembers
    {
        [STAThread]
        static void Main(string[] args)
        {
            // Initializes a new instance of the KeySizes class with the
            // specified key values.
            int minSize = 64;
            int maxSize = 1024;
            int skipSize = 64;
            KeySizes keySizes = new KeySizes(minSize, maxSize, skipSize);

            // Show the values of the keys.
            ShowKeys(new KeySizes[1]{keySizes}, "Custom Keys");

            // Create a new symmetric algorithm and display its key values.
            Aes aes = Aes.Create();
            ShowKeys(aes.LegalKeySizes, aes.ToString());
            Console.WriteLine("aes.blocksize:" + aes.BlockSize);

            // Create a new RSA algorithm and display its key values.
            RSA rsa = RSA.Create();
            ShowKeys(rsa.LegalKeySizes, rsa.ToString());
            Console.WriteLine("RSA KeySize = " + 
                rsa.KeySize);

            Console.WriteLine("This sample completed successfully; " +
                "press Enter to exit.");
            Console.ReadLine();
        }

        // Display specified KeySize properties to the console.
        private static void ShowKeys(KeySizes[] keySizes, string objectName)
        {
            // Retrieve the first KeySizes in the array.
            KeySizes firstKeySize = keySizes[0];

            // Retrieve the minimum key size in bits.
            int minKeySize = firstKeySize.MinSize;
                
            // Retrieve the maximum key size in bits.
            int maxKeySize = firstKeySize.MaxSize;
                
            // Retrieve the interval between valid key size in bits.
            int skipKeySize = firstKeySize.SkipSize;

            Console.Write("\n KeySizes retrieved from the ");
            Console.WriteLine(objectName + " object.");
            Console.WriteLine("Minimum key size bits: " + minKeySize);
            Console.WriteLine("Maximum key size bits: " + maxKeySize);
            Console.WriteLine("Interval between key size bits: " + 
                skipKeySize);
        }
    }
}
//
// This sample produces the following output:
//
// KeySizes retrieved from the Custom Keys object.
// Minimum key size bits: 64
// Maximum key size bits: 1024
// Interval between key size bits: 64
// 
// KeySizes retrieved from the System.Security.Cryptography.Aes
// object.
// Minimum key size bits: 128
// Maximum key size bits: 256
// Interval between key size bits: 64
// aes.blocksize:128
// 
// KeySizes retrieved from the
// System.Security.Cryptography.RSA object.
// Minimum key size bits: 512
// Maximum key size bits: 16384
// Interval between key size bits: 64
// RSA KeySize = 2048
// This sample completed successfully; press Enter to exit.

コンストラクター

KeySizes(Int32, Int32, Int32)

指定されたキー値で、KeySizes クラスの新しいインスタンスを初期化します。

プロパティ

MaxSize

最大キー サイズを指定します。

MinSize

最小キー サイズを指定します。

SkipSize

有効なキー サイズ間の間隔を指定します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1

こちらもご覧ください