提高Windows 产品密钥安全性

Windows产品密钥解析
本文介绍了一款名为WindowsProductKeyFinder的工具,该工具能够从Windows系统中读取并解码产品密钥。通过解析注册表中的DigitalProductId值,这款软件可以在XP、Vista和Windows7等操作系统上运行。文章还提供了防止密钥被恶意读取的方法。

  今天无意中在CodePlex 发现一个叫Windows Product Key Finder 的项目,从名字就可以看出它的用途。通过这款软件可以轻松的获取本地Windows 的产品密钥。当然对于找不到密钥光盘的人来说这当然是款实用的工具,但如果到了某些图谋不轨的人手里那您的产品密钥必定要受到威胁。

     阅读了项目源代码后,其实程序的核心也是最有价值的部分就是去解码\\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion 中的DigitalProductId 值。如下代码所示:

public static string DecodeProductKey(byte[] digitalProductId)
{
    // Offset of first byte of encoded product key in 
    // 'DigitalProductIdxxx" REG_BINARY value. Offset = 34H.
    const int keyStartIndex = 52;
    // Offset of last byte of encoded product key in 
    // 'DigitalProductIdxxx" REG_BINARY value. Offset = 43H.
    const int keyEndIndex = keyStartIndex + 15;
    // Possible alpha-numeric characters in product key.
    char[] digits = new char[]
    {
        'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'P', 'Q', 'R', 
        'T', 'V', 'W', 'X', 'Y', '2', '3', '4', '6', '7', '8', '9',
    };
    // Length of decoded product key
    const int decodeLength = 29;
    // Length of decoded product key in byte-form.
    // Each byte represents 2 chars.
    const int decodeStringLength = 15;
    // Array of containing the decoded product key.
    char[] decodedChars = new char[decodeLength];
    // Extract byte 52 to 67 inclusive.
    ArrayList hexPid = new ArrayList();
    for (int i = keyStartIndex; i <= keyEndIndex; i++)
    {
        hexPid.Add(digitalProductId[i]);
    }
    for (int i = decodeLength - 1; i >= 0; i--)
    {
        // Every sixth char is a separator.
        if ((i + 1) % 6 == 0)
        {
            decodedChars[i] = '-';
        }
        else
        {
            // Do the actual decoding.
            int digitMapIndex = 0;
            for (int j = decodeStringLength - 1; j >= 0; j--)
            {
                int byteValue = (digitMapIndex << 8) | (byte)hexPid[j];
                hexPid[j] = (byte)(byteValue / 24);
                digitMapIndex = byteValue % 24;
                decodedChars[i] = digits[digitMapIndex];
            }
        }
    }
    return new string(decodedChars);
}

     最后将读取出的DigitalProductId 值(Byte)赋给DecodeProductKey 方法即可算出Windows 产品密钥。项目描述中提到该程序在XP、Vista、Windows 7 系统上均可运行。

RegistryKey hklm = Registry.LocalMachine;
hklm = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
byte[] digitalProductId = hklm.GetValue("DigitalProductId") as byte[];
textBox1.Text = DecodeProductKey(digitalProductId);

     由此可见简单几行代码就可以使产品密钥落入他人之手,并且这类程序在网上还有很多。对于Vista、Windows 7 用户来说建议使用slmgr /cpky 命令对产品密钥进行一下处理,详细内容请参考《Windows 7 产品密钥是否安全》。从注册表清除产品密钥信息后,再运行该程序便会出现下图效果,产品密钥将全部显示为字母“B”,这样您就不必担心产品密钥的安全性了。

PK





本文转自Gnie博客园博客,原文链接:http://www.cnblogs.com/gnielee/archive/2010/06/07/fetch-productkey-via-csharp.html,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值