gpt4 book ai didi

java - 使用 Java 加密 RDP 密码

转载 作者:太空宇宙 更新时间:2023-11-04 07:33:13 25 4
gpt4 key购买 nike

我已经尝试过 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 密码哈希器实用程序生成的真实密码不匹配。有谁知道可以加密密码的解决方案或 CLI 实用程序?

最佳答案

这是我的工作解决方案(您需要 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";
}
}

关于java - 使用 Java 加密 RDP 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17386617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com