AsymmetricAlgorithm::KeySize Property
Gets or sets the size, in bits, of the key modulus used by the asymmetric algorithm.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System::Int32The size, in bits, of the key modulus used by the asymmetric algorithm.
| Exception | Condition |
|---|---|
| CryptographicException | The key modulus size is invalid. |
The valid key sizes are specified by the particular implementation of the asymmetric algorithm and are listed in the LegalKeySizes property.
The following code example demonstrates how to override the KeySize property to verify that it falls within the range identified in the local keySizes member variable. This code example is part of a larger example provided for the AsymmetricAlgorithm class.
public: property int KeySize { virtual int get() override { return KeySizeValue; } virtual void set(int value) override { for (int i = 0; i < customValidKeySizes->Length; i++) { if (customValidKeySizes[i]->SkipSize == 0) { if (customValidKeySizes[i]->MinSize == value) { KeySizeValue = value; return; } } else { for (int j = customValidKeySizes[i]->MinSize; j <= customValidKeySizes[i]->MaxSize; j += customValidKeySizes[i]->SkipSize) { if (j == value) { KeySizeValue = value; return; } } } } // If the key does not fall within the range identified // in the keySizes member variable, throw an exception. throw gcnew CryptographicException("Invalid key size."); } }
Available since 1.1
Windows Phone Silverlight
Available since 7.1