解密使用MS DPAPI和JNA加密的数据 [英] Decrypt Data which was encrypted with MS DPAPI with JNA

查看:100
本文介绍了解密使用MS DPAPI和JNA加密的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以解密使用MS DPAPI加密的数据?例如,我想从Windows注册表中解密数字证书.

is it possible to decrypt data which was encrypted with MS DPAPI? For example i want to decrypt a digital certificate from the windows registry.

byte[] byteArray = (byte[]) Advapi32Util.registryGetValue(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\SystemCertificates\\AuthRoot\\Certificates\\02FAF3E291435468607857694DF5E45B68851868", "Blob");

byte[] decrypted = Crypt32Util.cryptUnprotectData(byteArray);

String stringDecrypted = new String(decrypted);
System.out.println(stringDecrypted);

但是我得到了Win32异常:线程"main"中的异常com.sun.jna.platform.win32.Win32Exception:数据无效.

But i get an Win32 Exception: Exception in thread "main" com.sun.jna.platform.win32.Win32Exception: Data are invalid.

我没有找到任何有关此异常的信息.那么,这意味着什么?我可以像我想要的那样解密这些文件吗?还是不可能?

I don't found any information about this Exception. So what das this mean?? And could i decrypt these files like i want it or is it not possible?

感谢帮助!

推荐答案

根据

According to the MSDN documentation, you're missing six additional arguments to cryptUnprotectData.

即使这些参数标记为可选",您仍然需要在接口方法签名中声明它们.

Even if these arguments are marked "optional", you still need to declare them in your interface method signature.

更新

基于MSDN文档:

BOOL WINAPI CryptUnprotectData(
  _In_        DATA_BLOB *pDataIn,
  _Out_opt_   LPWSTR *ppszDataDescr,
  _In_opt_    DATA_BLOB *pOptionalEntropy,
  _Reserved_  PVOID pvReserved,
  _In_opt_    CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct,
  _In_        DWORD dwFlags,
  _Out_       DATA_BLOB *pDataOut
);

第二,第三,第四和第五个自变量可能是null.第六个参数可以可能为零.最后一个参数需要适当分配

The second, third, fourth, and fifth arguments can probably be null. The sixth argument can probably be zero. The final argument needs to be an appropriately allocated DATA_BLOB where the function can store its results (this structure is defined in JNA's platform.jar). Don't forget to free the DATA_BLOB's pbData field when you're done with it, passing its value to LocalFree.

这篇关于解密使用MS DPAPI和JNA加密的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆