Windows7 注册表byte[]密钥解密
2015-01-24 14:04
211 查看
注册表位置:
\\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
值位置
DigitalProductId
从注册表中获取密钥的byte[]:
RegistryKey hklm = Registry.LocalMachine;
hklm = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
byte[] digitalProductId = hklm.GetValue("DigitalProductId") as byte[];
textBox1.Text = DecodeProductKey(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);
}
\\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion
值位置
DigitalProductId
从注册表中获取密钥的byte[]:
RegistryKey hklm = Registry.LocalMachine;
hklm = hklm.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
byte[] digitalProductId = hklm.GetValue("DigitalProductId") as byte[];
textBox1.Text = DecodeProductKey(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);
}
相关文章推荐
- 【转】windows7的桌面右键菜单的“新建”子菜单,在注册表哪个位置,如何在“新建"里面添加一个新项
- 密码学---非对称密码的加密解密采用公钥还是密钥
- Windows7下无法编辑注册表的问题
- java加解密-密钥长度限制问题
- 通过代理截取并修改非对称密钥加密信息 加密、解密算法总的来说可以分称对称密钥加密以及非对称密钥加密算法。 对称密钥加密算法要求加密和解密都用同一把密钥。这可能是对称密码体制的主要弱点(为了让对方能够
- 数字签名的加密解密过程 和 私有密钥的加密解密过程
- 加密解密学习第一篇;生成,检查rsa密钥
- C# 基于密钥的64位加密与解密方法(原创)
- 加密,解密 自定义密钥
- 带密钥的加解密
- Java 10进制byte数组与16进制byte数组互转 及 在DES加解密中的使用
- Windows7下注册表修改右键新建快捷键
- PHP通过OpenSSL生成证书、密钥并且加密解密数据
- iOS被爆存在安全漏洞,邮箱附件无需使用密钥即可解密
- 不改动注册表让windows7时间栏显示星期信息的方法
- 文件加密和解密 - 密钥存储
- Windows7升级密钥输入错误如何修改
- OPENSSL RSA加密同一程序多次加载密钥会加密解密出错
- rsa加解密密钥生成命令
- Win10系统盘启用BitLocker加密详细方法及使用备份密钥解密BitLocker(多图)