3DES has not been deprecated, nor has DPAPI. While the 3DES algorithm is not ideal and should not be used in new designs where avoidable, the best attack we know against is is a meet-in-the-middle attack which requires 512PiB of error-correcting RAM and 2112 + 256 operations. Considering other possible attacks against DPAPI, e.g. using the mimikatz DPAPI module on a running system, this seems rather outlandish.
CNG-DPAPI (which is called DPAPI-NG now) would be a better choice for modern designs. Unfortunately the examples out there are fairly scant, leaving you to work a lot of things out on your own. The following is a high-level example of how you might implement secret storage using DPAPI-NG:
- Call
NCryptCreateProtectionDescriptor
with dwFlags
set to 0 and pwszDescriptorString
set to a protection descriptor string. To protect the data such that only the current user can access it, use "LOCAL=user"
, and for machine-wide protection use "LOCAL=machine"
. You can also encrypt to a set of web credentials under an ASP context, a certificate from the certificate store, a domain user by specifying a SID, or you can specify a fully custom security descriptor using SSDL.
- Call
NCryptProtectSecret
, passing in the handle you got from the above operation, in order to encrypt small amounts of data (e.g. a credential string)
- Call
NCryptStreamOpenToProtect
if you want to encrypt a lot of data. This opens up a stream that you can write data into via NCryptStreamUpdate
.
- Call
NCryptUnprotectSecret
in order to decrypt data that was encrypted with NCryptProtectSecret
.
- Call
NCryptStreamOpenToUnprotect
to decrypt data that was encrypted with NCryptStreamOpenToProtect
. Again, NCryptStreamUpdate
is used here.
- If you used any of the stream functions, call
NCryptStreamClose
to close them.
- Call
NCryptCloseProtectionDescriptor
to close the protection descriptor handle you created in the first step.
DPAPI-NG is still affected by tools such as mimikatz, but that's just an inherent part of how operating system security works - if an attacker is running code as an administrator, they have won.
The old API for DPAPI is much simpler, but the new API has more comprehensive support for different security scenarios as described above. The cryptography in use is certainly not the weakest link in the chain for either API.