提高Windows 產品金鑰安全性

來源:互聯網
上載者:User

     今天無意中在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”,這樣您就不必擔心產品金鑰的安全性了。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.