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);
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?
Thnaks for help!
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.
UPDATE
Based on the MSDN documentation:
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 allocatedDATA_BLOB
where the function can store its results (this structure is defined in JNA'splatform.jar
). Don't forget to free theDATA_BLOB
'spbData
field when you're done with it, passing its value toLocalFree
.