Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / mscorlib / system / security / cryptography / rc2.cs
bloba33eb7255d1fe82282b53d12dc466fb4b3bd41ba
1 // ==++==
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // ==--==
6 // <OWNER>Microsoft</OWNER>
7 //
9 //
10 // RC2.cs
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
29 protected RC2() {
30 KeySizeValue = 128;
31 BlockSizeValue = 64;
32 FeedbackSizeValue = BlockSizeValue;
33 LegalBlockSizesValue = s_legalBlockSizes;
34 LegalKeySizesValue = s_legalKeySizes;
38 // public properties
41 public virtual int EffectiveKeySize {
42 get {
43 if (EffectiveKeySizeValue == 0) return KeySizeValue;
44 return EffectiveKeySizeValue;
46 set {
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"));
53 } else {
54 if (ValidKeySize(value))
55 EffectiveKeySizeValue = value;
56 else
57 throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
62 public override int KeySize {
63 get { return KeySizeValue; }
64 set {
65 if (value < EffectiveKeySizeValue) throw new CryptographicException(Environment.GetResourceString("Cryptography_RC2_EKSKS"));
66 base.KeySize = value;
71 // public methods
74 new static public RC2 Create() {
75 #if FULL_AOT_RUNTIME
76 return new System.Security.Cryptography.RC2CryptoServiceProvider ();
77 #else
78 return Create("System.Security.Cryptography.RC2");
79 #endif
82 new static public RC2 Create(String AlgName) {
83 return (RC2) CryptoConfig.CreateFromName(AlgName);