【问题标题】:Encrypt RDP password with Java使用 Java 加密 RDP 密码
【发布时间】:2013-09-27 16:18:12
【问题描述】:

我已经尝试过 SO 的其他解决方案,例如:

String password ="pwd";
        WinCrypt.DATA_BLOB pDataIn = new WinCrypt.DATA_BLOB(password.getBytes(Charset.forName("UTF-16LE")));
        WinCrypt.DATA_BLOB pDataEncrypted = new WinCrypt.DATA_BLOB();
        System.out.println(Crypt32.INSTANCE.CryptProtectData(pDataIn, "psw",
                null, null, null, WinCrypt.CRYPTPROTECT_UI_FORBIDDEN, pDataEncrypted));
        StringBuffer epwsb = new StringBuffer();
        byte[] pwdBytes= new byte [pDataEncrypted.cbData];
        pwdBytes=pDataEncrypted.getData();
        Formatter formatter = new Formatter(epwsb);
        for ( final byte b : pwdBytes ) {
            formatter.format("%02X", b);
        }
        System.out.println("password 51:b:"+ epwsb.toString());

Crypt32Util.cryptProtectData("12345".getBytes("UTF-16LE"), null, 0, "psw", null);

但是每次我运行它们时,它们都会给出不同的结果,并且它们与由 MSTSC 保存或由 RDP Password Hasher 实用程序生成的真实密码不匹配。 有谁知道可以加密密码的解决方案或 CLI 实用程序?

【问题讨论】:

  • "每次运行它们都会给出不同的结果" hash 而不是加密形式吗?如果它是一个哈希,那么它可以随时间变化是很正常的,这个哈希是加盐的......

标签: java rdp mstsc


【解决方案1】:

这是我的工作解决方案(您需要 JNA 平台才能使其工作):

    private static String ToHexString(byte[] bytes) {   
        StringBuilder sb = new StringBuilder();   
        Formatter formatter = new Formatter(sb);   
        for (byte b : bytes) {
            formatter.format("%02x", b);   
        }
        formatter.close();
        return sb.toString();   
    }  

    private String cryptRdpPassword(String pass) {
        try {
            return ToHexString(Crypt32Util.cryptProtectData(pass.getBytes("UTF-16LE"), null, 0, "psw", null));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return "ERROR";
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多