【问题标题】:Java CryptUnprotectData Windows WiFi PasswordsJava CryptUnprotectData Windows WiFi 密码
【发布时间】:2017-08-17 22:14:03
【问题描述】:

我正在尝试使用 Java 在同一台机器上解密 Windows WiFi 密码,该密码应该与 cryptUnprotectData() 一起使用,但我收到以下错误:

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 密码的信息。为什么我直接从XMLkeyMaterial标签复制数据无效?我是这台机器的管理员,密码是我的用户帐户。

更新

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)

具体是什么意思?缺少权限?

【问题讨论】:

    标签: java c++ windows passwords wifi


    【解决方案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?

    【讨论】:

    • 确实,但现在我收到此错误:“密钥在指定状态下无效。”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多