【问题标题】:How can i encrypt a text to wpa2 password (MasterKey) in c#如何在 c# 中将文本加密为 wpa2 密码(MasterKey)
【发布时间】:2015-02-20 10:16:22
【问题描述】:

我正在尝试制作一个尝试破解 WPA2 密钥的代码,因为我在想我应该首先将我想尝试的文本密码转换为 WAP2 密钥,而不是检查它是否相同(比如md5或其他),所以我需要知道WPA2密钥或密码或所谓的MasterKey是如何制作的,请

【问题讨论】:

    标签: c# passwords key wifi


    【解决方案1】:

    尝试使用此代码

    using System;
    using System.Reflection;
    using System.Security.Cryptography;
    using System.Text;
    
    namespace WPA2MasterKeyGeneRator
    {
        public class WpaKeyCalculator
        {
            static void Main()
            {
                var keyCalculator = new WpaKeyCalculator("dlink");
    
                var key = keyCalculator.GetWpaMasterKey("1234567");
    
                //print hex
                //you can check results using online calculator here http://jorisvr.nl/wpapsk.html
                Console.WriteLine(BitConverter.ToString(key).Replace("-", ""));
            }
    
            private readonly byte[] _ssidBytes;
    
            public WpaKeyCalculator(string ssidName)
            {
                _ssidBytes = Encoding.ASCII.GetBytes(ssidName);
            }
    
            private byte[] GetWpaMasterKey(string password)
            {
                Rfc2898DeriveBytes pbkdf2;
    
                //little magic here
                //Rfc2898DeriveBytes class has restriction of salt size to >= 8
                //but rfc2898 not (see http://www.ietf.org/rfc/rfc2898.txt)
                //we use Reflection to setup private field to avoid this restriction
    
                if (_ssidBytes.Length >= 8)
                    pbkdf2 = new Rfc2898DeriveBytes(password, _ssidBytes, 4096);
                else
                {
                    //use dummy salt here, we replace it later vie reflection
                    pbkdf2 = new Rfc2898DeriveBytes(password, new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 4096);
    
                    var saltField = typeof(Rfc2898DeriveBytes).GetField("m_salt", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
                    saltField.SetValue(pbkdf2, _ssidBytes);
                }
    
                //get 256 bit PMK key
                return pbkdf2.GetBytes(32);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2013-04-16
      • 1970-01-01
      • 2012-04-14
      • 2017-03-18
      • 2016-12-01
      • 2013-09-06
      相关资源
      最近更新 更多