我尝试使用可能与cryptUnprotectData()
一起使用的Java在同一台计算机上解密Windows WiFi密码,但我收到以下错误:
Exception in thread "main" com.sun.jna.platform.win32.Win32Exception: The data is invalid.
at com.sun.jna.platform.win32.Crypt32Util.cryptUnprotectData(Crypt32Util.java:128)
at com.sun.jna.platform.win32.Crypt32Util.cryptUnprotectData(Crypt32Util.java:103)
at com.sun.jna.platform.win32.Crypt32Util.cryptUnprotectData(Crypt32Util.java:90)
我正在使用这个Java代码:
String encryptedWirelessKey = "01000000D08C9DDF0115D1118C7A00C0***TRUNCATED***";
byte[] bytes = Crypt32Util.cryptUnprotectData(encryptedWirelessKey.getBytes(Charset.defaultCharset()));
System.out.println(new String(bytes));
Here您可以详细了解Windows存储WiFi密码的位置。当我直接从XML
keyMaterial
标签复制数据时,为什么数据无效?我是机器的管理员,密码是我的用户帐户。
更新:
import com.sun.jna.platform.win32.Crypt32Util;
public class Testing
{
public static void main(String[] arguments) throws Exception
{
String encryptedWirelessKey = "01000000D08C9DDF0115D1118C7A00C0***TRUNCATED***";
byte[] bytes = Crypt32Util.cryptUnprotectData(hexStringToByteArray(encryptedWirelessKey));
System.out.println(new String(bytes));
}
private static byte[] hexStringToByteArray(String s) {
int len = s.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i+1), 16));
}
return data;
}
}
这会引发以下异常:
Exception in thread "main" com.sun.jna.platform.win32.Win32Exception: Key not valid for use in specified state.
at com.sun.jna.platform.win32.Crypt32Util.cryptUnprotectData(Crypt32Util.java:128)
at com.sun.jna.platform.win32.Crypt32Util.cryptUnprotectData(Crypt32Util.java:103)
at com.sun.jna.platform.win32.Crypt32Util.cryptUnprotectData(Crypt32Util.java:90)
究竟是什么意思?缺乏权限?
答案 0 :(得分:1)
你在十六进制字符串上使用getBytes()
,当你解析十六进制字符串为字节时。
从以下链接中选择您喜欢的方式。
In Java, how do I convert a hex string to a byte[]?
Convert a string representation of a hex dump to a byte array using Java?