3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // <OWNER>Microsoft</OWNER>
13 namespace System
.Security
.Cryptography
{
14 [System
.Runtime
.InteropServices
.ComVisible(true)]
15 public abstract class RC2
: SymmetricAlgorithm
17 protected int EffectiveKeySizeValue
;
18 private static KeySizes
[] s_legalBlockSizes
= {
19 new KeySizes(64, 64, 0)
21 private static KeySizes
[] s_legalKeySizes
= {
22 new KeySizes(40, 1024, 8) // 1024 bits is theoretical max according to the RFC
26 // protected constructors
32 FeedbackSizeValue
= BlockSizeValue
;
33 LegalBlockSizesValue
= s_legalBlockSizes
;
34 LegalKeySizesValue
= s_legalKeySizes
;
41 public virtual int EffectiveKeySize
{
43 if (EffectiveKeySizeValue
== 0) return KeySizeValue
;
44 return EffectiveKeySizeValue
;
47 if (value > KeySizeValue
) {
48 throw new CryptographicException(Environment
.GetResourceString("Cryptography_RC2_EKSKS"));
49 } else if (value == 0) {
50 EffectiveKeySizeValue
= value;
51 } else if (value < 40) {
52 throw new CryptographicException(Environment
.GetResourceString("Cryptography_RC2_EKS40"));
54 if (ValidKeySize(value))
55 EffectiveKeySizeValue
= value;
57 throw new CryptographicException(Environment
.GetResourceString("Cryptography_InvalidKeySize"));
62 public override int KeySize
{
63 get { return KeySizeValue; }
65 if (value < EffectiveKeySizeValue
) throw new CryptographicException(Environment
.GetResourceString("Cryptography_RC2_EKSKS"));
74 new static public RC2
Create() {
76 return new System
.Security
.Cryptography
.RC2CryptoServiceProvider ();
78 return Create("System.Security.Cryptography.RC2");
82 new static public RC2
Create(String AlgName
) {
83 return (RC2
) CryptoConfig
.CreateFromName(AlgName
);