private void TranslateEncryptionKey(ref WLANConfiguration config, string key, AuthenticationMode authMode, WEPStatus privacyMode)
        {
            if (privacyMode == WEPStatus.WEPEnabled)
            {
                if ((key.Length != 10) && (key.Length != 26))
                {
                    throw new ArgumentException("The encryption key for WEP must be either 10 or 26 characters");
                }

                byte[] keyMaterial = HexStringToBytes(key);
                config.KeyMaterial = keyMaterial;

                config.CtlFlags |= WZCControl.WEPKPresent | WZCControl.WEPKXFormat;
                if (key.Length == 10)
                {
                    config.CtlFlags |= WZCControl.WEPK40Bit;
                }

                config.KeyMaterial = EncryptKeyMaterial(keyMaterial);
            }
            else if ((privacyMode == WEPStatus.AESEnabled) || (privacyMode == WEPStatus.TKIPEnabled))
            {
                config.KeyLength = key.Length;
                if ((config.KeyLength < 8) || (config.KeyLength > 63))
                {
                    throw new ArgumentException("The encryption key for WPA-PSK/TKIP must be either between 8 and 63");
                }
                WZC.WZCPassword2Key(ref config, key);

                config.CtlFlags      |= WZCControl.WEPKPresent | WZCControl.WEPKXFormat | WZCControl.ONEXEnabled;
                config.WPAMCastCipher = (int)WEPStatus.TKIPEnabled;

                config.KeyMaterial = EncryptKeyMaterial(config.KeyMaterial);
            }
        }
        /// <summary>
        /// The ProcessKey routine makes necessary modifications
        /// to the key material of a WPA key before it is passed
        /// to WZC routines.  The processing done to it depends
        /// on how it was generated.
        /// </summary>
        /// <param name="kt">
        /// The key type, indicating how the key material in
        /// the structure was originally generated
        /// </param>
        /// <param name="config">
        /// The configuration being changed
        /// </param>
        /// <param name="passphrase">
        /// For WPA-PSK passphrase type, the passphrase.
        /// </param>
        internal void ProcessKey(KeyType kt, ref WLANConfiguration config,
                                 string passphrase)
        {
            // Define fake key material for 'encrypting' the
            // keys.
            byte[] chFakeKeyMaterial = new byte[] { 0x56, 0x09, 0x08, 0x98, 0x4D, 0x08, 0x11, 0x66, 0x42, 0x03, 0x01, 0x67, 0x66 };
            byte[] key;
            uint   i;

            switch (kt)
            {
            case KeyType.WPAPassphrase:
                // We set this explicitly here.  It was set
                // out of line in the NetUI code.
                config.Privacy = WEPStatus.TKIPEnabled;

                config.KeyLength = WLANConfiguration.WZCCTL_MAX_WEPK_MATERIAL;
                config.CtlFlags |= WZCControl.WEPKXFormat | WZCControl.ONEXEnabled | WZCControl.WEPKPresent;

                WZC.WZCPassword2Key(ref config, passphrase);

                // Note that, since the config structure doesn't
                // actually have a byte[] for key material, we
                // can't modify bytes of that 'array' in-place.
                key = config.KeyMaterial;
                for (i = 0; i < WLANConfiguration.WZCCTL_MAX_WEPK_MATERIAL; i++)
                {
                    key[i] ^= chFakeKeyMaterial[(7 * i) % 13];
                }
                config.KeyMaterial = key;

                config.EapolParams.EapFlags    = EAPFlags.Enabled;
                config.EapolParams.EapType     = EAPType.TLS;
                config.EapolParams.Enable8021x = true;
                // config.WPAMCastCipher = Ndis802_11Encryption2Enabled;
                break;

            case KeyType.WPABinary:
                // We set this explicitly here.  It was set
                // out of line in the NetUI code.
                config.Privacy = WEPStatus.TKIPEnabled;

                config.KeyLength = WLANConfiguration.WZCCTL_MAX_WEPK_MATERIAL;
                config.CtlFlags |= WZCControl.WEPKPresent;

                // Note that, since the config structure doesn't
                // actually have a byte[] for key material, we
                // can't modify bytes of that 'array' in-place.
                key = config.KeyMaterial;
                for (i = 0; i < WLANConfiguration.WZCCTL_MAX_WEPK_MATERIAL; i++)
                {
                    config.KeyMaterial[i] ^= chFakeKeyMaterial[(7 * i) % 13];
                }
                config.KeyMaterial = key;

                config.EapolParams.EapFlags    = EAPFlags.Enabled;
                config.EapolParams.EapType     = EAPType.TLS;
                config.EapolParams.Enable8021x = true;
                // config.WPAMCastCipher = Ndis802_11Encryption2Enabled;
                break;
            }
        }