用Java加密RDP密码
我已经尝试过SO的其他解决方案,例如:用Java加密RDP密码,java,rdp,mstsc,Java,Rdp,Mstsc,我已经尝试过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(
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());
或
但是每次我运行它们时,它们都会给出不同的结果,并且它们与MSTSC保存的或RDP密码哈希工具生成的真实密码不匹配。
有人知道可以加密密码的解决方案或CLI实用程序吗?这是我的工作解决方案(您需要JNA平台才能工作):
以下是我的工作解决方案(您需要JNA平台,以使其正常工作):
“每次运行它们时,它们都会给出不同的结果”“每次运行它们时,它们都会给出不同的结果”
Crypt32Util.cryptProtectData("12345".getBytes("UTF-16LE"), null, 0, "psw", null);
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";
}
}