using System; using System.Runtime.InteropServices; namespace System.Security.Cryptography { /// Represents the base class for the Data Encryption Standard (DES) algorithm from which all implementations must derive. // Token: 0x020004F6 RID: 1270 [ComVisible(true)] public abstract class DES : SymmetricAlgorithm { /// Initializes a new instance of the class. // Token: 0x06002EF4 RID: 12020 RVA: 0x00096CB4 File Offset: 0x00094EB4 protected DES() { this.KeySizeValue = 64; this.BlockSizeValue = 64; this.FeedbackSizeValue = 8; this.LegalKeySizesValue = new KeySizes[1]; this.LegalKeySizesValue[0] = new KeySizes(64, 64, 0); this.LegalBlockSizesValue = new KeySizes[1]; this.LegalBlockSizesValue[0] = new KeySizes(64, 64, 0); } /// Creates an instance of a cryptographic object to perform the Data Encryption Standard () algorithm. /// A cryptographic object. /// /// /// // Token: 0x06002EF6 RID: 12022 RVA: 0x00096D58 File Offset: 0x00094F58 public new static DES Create() { return DES.Create("System.Security.Cryptography.DES"); } /// Creates an instance of a cryptographic object to perform the specified implementation of the Data Encryption Standard () algorithm. /// A cryptographic object. /// The name of the specific implementation of to use. // Token: 0x06002EF7 RID: 12023 RVA: 0x00096D64 File Offset: 0x00094F64 public new static DES Create(string algName) { return (DES)CryptoConfig.CreateFromName(algName); } /// Determines whether the specified key is weak. /// true if the key is weak; otherwise, false. /// The secret key to test for weakness. /// The size of the parameter is not valid. // Token: 0x06002EF8 RID: 12024 RVA: 0x00096D74 File Offset: 0x00094F74 public static bool IsWeakKey(byte[] rgbKey) { if (rgbKey == null) { throw new CryptographicException(Locale.GetText("Null Key")); } if (rgbKey.Length != 8) { throw new CryptographicException(Locale.GetText("Wrong Key Length")); } for (int i = 0; i < rgbKey.Length; i++) { int num = (int)(rgbKey[i] | 17); if (num != 17 && num != 31 && num != 241 && num != 255) { return false; } } for (int j = 0; j < DES.weakKeys.Length >> 3; j++) { int k; for (k = 0; k < rgbKey.Length; k++) { if ((rgbKey[k] ^ DES.weakKeys[j, k]) > 1) { break; } } if (k == 8) { return true; } } return false; } /// Determines whether the specified key is semi-weak. /// true if the key is semi-weak; otherwise, false. /// The secret key to test for semi-weakness. /// The size of the parameter is not valid. // Token: 0x06002EF9 RID: 12025 RVA: 0x00096E54 File Offset: 0x00095054 public static bool IsSemiWeakKey(byte[] rgbKey) { if (rgbKey == null) { throw new CryptographicException(Locale.GetText("Null Key")); } if (rgbKey.Length != 8) { throw new CryptographicException(Locale.GetText("Wrong Key Length")); } for (int i = 0; i < rgbKey.Length; i++) { int num = (int)(rgbKey[i] | 17); if (num != 17 && num != 31 && num != 241 && num != 255) { return false; } } for (int j = 0; j < DES.semiWeakKeys.Length >> 3; j++) { int k; for (k = 0; k < rgbKey.Length; k++) { if ((rgbKey[k] ^ DES.semiWeakKeys[j, k]) > 1) { break; } } if (k == 8) { return true; } } return false; } /// Gets or sets the secret key for the Data Encryption Standard () algorithm. /// The secret key for the algorithm. /// An attempt was made to set the key to null. /// An attempt was made to set a key whose length is not equal to . /// An attempt was made to set a weak key (see ) or a semi-weak key (see ). // Token: 0x1700094B RID: 2379 // (get) Token: 0x06002EFA RID: 12026 RVA: 0x00096F34 File Offset: 0x00095134 // (set) Token: 0x06002EFB RID: 12027 RVA: 0x00096F58 File Offset: 0x00095158 public override byte[] Key { get { if (this.KeyValue == null) { this.GenerateKey(); } return (byte[])this.KeyValue.Clone(); } set { if (value == null) { throw new ArgumentNullException("Key"); } if (value.Length != 8) { throw new ArgumentException(Locale.GetText("Wrong Key Length")); } if (DES.IsWeakKey(value)) { throw new CryptographicException(Locale.GetText("Weak Key")); } if (DES.IsSemiWeakKey(value)) { throw new CryptographicException(Locale.GetText("Semi Weak Key")); } this.KeyValue = (byte[])value.Clone(); } } // Token: 0x04001326 RID: 4902 private const int keySizeByte = 8; // Token: 0x04001327 RID: 4903 internal static readonly byte[,] weakKeys = new byte[,] { { 1, 1, 1, 1, 1, 1, 1, 1 }, { 31, 31, 31, 31, 15, 15, 15, 15 }, { 225, 225, 225, 225, 241, 241, 241, 241 }, { byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue } }; // Token: 0x04001328 RID: 4904 internal static readonly byte[,] semiWeakKeys = new byte[,] { { 0, 30, 0, 30, 0, 14, 0, 14 }, { 0, 224, 0, 224, 0, 240, 0, 240 }, { 0, 254, 0, 254, 0, 254, 0, 254 }, { 30, 0, 30, 0, 14, 0, 14, 0 }, { 30, 224, 30, 224, 14, 240, 14, 240 }, { 30, 254, 30, 254, 14, 254, 14, 254 }, { 224, 0, 224, 0, 240, 0, 240, 0 }, { 224, 30, 224, 30, 240, 14, 240, 14 }, { 224, 254, 224, 254, 240, 254, 240, 254 }, { 254, 0, 254, 0, 254, 0, 254, 0 }, { 254, 30, 254, 30, 254, 14, 254, 14 }, { 254, 224, 254, 224, 254, 240, 254, 240 } }; } }