RC2.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // System.Security.Cryptography.RC2.cs
  3. //
  4. // Authors:
  5. // Andrew Birkett ([email protected])
  6. // Sebastien Pouliot ([email protected])
  7. //
  8. using System;
  9. namespace System.Security.Cryptography {
  10. public abstract class RC2 : SymmetricAlgorithm {
  11. public static new RC2 Create ()
  12. {
  13. return Create ("System.Security.Cryptography.RC2");
  14. }
  15. public static new RC2 Create (string algName)
  16. {
  17. return (RC2) CryptoConfig.CreateFromName (algName);
  18. }
  19. protected int EffectiveKeySizeValue;
  20. public virtual int EffectiveKeySize {
  21. get {
  22. if (EffectiveKeySizeValue == 0)
  23. return KeySizeValue;
  24. else
  25. return EffectiveKeySizeValue;
  26. }
  27. set {
  28. if (!IsLegalKeySize (LegalKeySizesValue, value))
  29. throw new CryptographicException ("key size not supported by algorithm");
  30. EffectiveKeySizeValue = value;
  31. }
  32. }
  33. // Overridden, which makes me suspect it changes effective keysize too?
  34. public override int KeySize {
  35. get { return KeySizeValue; }
  36. set { KeySizeValue = value; }
  37. }
  38. public RC2 ()
  39. {
  40. KeySizeValue = 128;
  41. BlockSizeValue = 64;
  42. FeedbackSizeValue = 64;
  43. // The RFC allows keys of 1 to 128 bytes, but MS impl only supports
  44. // 40 to 128 bits, sigh.
  45. LegalKeySizesValue = new KeySizes[1];
  46. LegalKeySizesValue[0] = new KeySizes(40, 128, 8);
  47. LegalBlockSizesValue = new KeySizes[1];
  48. LegalBlockSizesValue[0] = new KeySizes(64, 64, 0);
  49. }
  50. }
  51. }