ASCII编码的字符串 KGS!@#$% 是使用的正确魔术常数
KGS!@#$%
使用字符串的前7个字符($ str1)作为键(末尾带有空字节)
然而,这是不正确的。密钥不是通过在末尾用单个0字节填充7个字节的部分输入来组成的,而是通过将输入分成8个7位块并将它们左移一次(产生8个字节)。
在PowerShell中实现这一点的最简单方法可能是使用字符串,所以我可能会这样做:
# Convert string to byte array $inBytes = $OEM.GetBytes($str1) # Create a binary string from our bytes $bitString = '' foreach($byte in $inBytes){ $bitstring += [convert]::ToString($byte, 2).PadLeft(8, '0') } # Partition the byte string into 7-bit chunks [byte[]]$key = $bitString -split '(?<=\G.{7}(?<!$))' |ForEach-Object { # Insert 0 as the least significant bit in each chunk # Convert resulting string back to [byte] [convert]::ToByte("${_}0", 2) } try{ # Create the first encryptor from our new key, and an empty IV [byte[]]$iv = ,0 * 8 $enc = $hasher.GetEncryptor($key, $iv) # Calculate half of the hash $block1 = $enc.TransformFinalBlock($plaintext, 0, 8) } finally{ # Dispose of the encryptor $enc.Dispose() }
然后重复一遍 $str2 并将结果块连接到完整的LM哈希
$str2