C# WEPkey 生成器






3.54/5 (9投票s)
2004年7月26日
2分钟阅读

85438

2801
用于保护您的无线局域网的 WepKey 生成器。
引言
无论您听到了关于无线网络 WEP(Wired Equivalent Privacy,有线等效保密)加密的什么负面评价,不使用它就是在自找麻烦。通常,设置起来快速且简单,而且至少它不会花你任何费用!
然而,生成要使用的随机 WEP 密钥可能很麻烦 - 很难想出新的密钥,如果您希望在您的无线网络上获得良好的安全性,您需要定期更改它们。 我在 Warewolf Labs 找到了一个基于 JavaScript 的 WepKey 生成器,并受到了启发,所以我不得不使用 C# 制作一个 WepKey 生成器。 整个代码是用 JavaScript 编写的,并且慷慨地免费提供了代码以供分发(非常感谢他们所做的出色工作!)JavaScript 中有几个方法调用在 .NET 框架中不存在,所以我不得不为它们创建一个等效的方法。 我必须做的第二件事是将整个重新生成的 C# 代码重新打包成面向对象的包装。 当您想要将 WepKey 类继承到您自己的项目中时,这会很方便。 使用此应用程序,您可以为您的无线局域网生成良好的、强大的 WEP 密钥! 有关 WEP 密钥设置和术语的良好入门知识可以在这里找到。
首先,这个应用程序可以分为两个部分
- 一、基于自定义密码创建 WepKey。
- 二、通过选择您的硬件所需的相应长度来生成伪随机 WepKey。
首先,我必须为我的应用程序创建一个资源来匹配输入的密码。 第一个数组是一个 char
数组,可以容纳最多 95 个最常用的 (ASCII) 字符。 第二个是一个 string
数组,其长度与 ASCII 数组相同。
/// <remarks>
/// Two public static array's for serving as a resource
/// witch will be used to match the input (string) value.
/// Both array's share the same index.
/// </remarks>
/// <summary>
/// These are the 95 most possible characters from witch
/// to choose for generating the WEP key.
/// </summary>
public static char [] asciiArray = new char[95] {
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')',
'*', '+', ',', '-', '.', '/','0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
'>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[',
'\\', ']', '^', '_', '\'', 'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', '{', '|', '}', '~'
};
/// <summary>
/// 95 HEX value's that uses the ASCII index from above.
/// </summary>
public static string [] hexArray = new string [95] {
"20","21","22","23","24","25","26","27","28","29",
"2A","2B","2C","2D","2E","2F","30","31","32","33",
"34","35","36","37","38","39","3A","3B","3C","3D",
"3E","3F","40","41","42","43","44","45","46","47",
"48","49","4A","4B","4C","4D","4E","4F","50","51",
"52","53","54","55","56","57","58","59","5A","5B",
"5C","5D","5E","5F","60","61","62","63","64","65",
"66","67","68","69","6A","6B","6C","6D","6E","6F",
"70","71","72","73","74","75","76","77","78","79",
"7A","7B","7C","7D","7E"
};
此应用程序中的第一个选项是通过输入密码来创建自定义 WepKey。 自定义密码字符串被分成字符,这些字符在 (ASCII) 资源数组中被单独匹配,并返回一个整数索引号。 此数字将由第二个方法 StringToHex
重新使用以收集 HEX 等效值,并将合并成一个字符串,最后将其返回给调用者。
/// <remarks>
/// This method actually iterates trough the length
/// of the passphrase to match each character in
/// the Resources.asciiArray using the method LocateAciiIndex.
/// Finally the actually result is matched in the Resources.hexArray
/// and returns the result in variable string Result.
/// Finally string Result is returned to the caller.
/// </remarks>
public string StringToHex() {
int i = (int)InitialValue.DefaultIntegerValue; int j = i;
string Result = string.Empty;
try {
for (i = (int)InitialValue.DefaultIntegerStartValue;
i < WepString.Length; i++) {
j = this.LocateAsciiIndex(WepString[i]);
Result += Resources.hexArray[j];
}
}
catch (System.IndexOutOfRangeException ex) {
Messaging.WepKeyMessage(ex.Message,
Messaging.MessageIcon.Critical());
}
return Result;
}
此应用程序中的第二个选项,可能是最强大的选项,是创建伪随机 WepKey。 它使用几乎相同的方法; 唯一的事情是 GenerateStrongKey
现在提供密码。
/// <remarks>
/// This method first clears the class string variable 'WepString';
/// then instatiate an Random object;
/// Then the speudo random generated integer is used
/// as an index to resolves an character
/// in Resources.asciiArray. The speudo random generated integer
/// is actually limited to the max length of Resources.asciiArray.
/// Foreach character resolved in Resources.asciiArray puts
/// the actually result in the class variable WepString.
/// Finally this method returns the combined character string.
/// </remarks>
/// <summary>
/// (5/13/16/29 bytes for 64/128/152/256-bit WEP
/// </summary>
public string GenerateStrongKey(int type) {
this.WepString = string.Empty;
Random rdm = new Random();
for (int i = (int)InitialValue.DefaultIntegerStartValue; i < type; i++) {
this.WepString +=
Resources.asciiArray[rdm.Next(Resources.asciiArray.Length)];
}
return this.StringToHex();
}
创建 WepKey 时,您必须考虑使用“强生成的 wepkey”来保护您自己,但这个选择由您决定!