How to decrypt data which is crypted by CryptProtectData function?

前端 未结 2 940
谎友^
谎友^ 2021-01-14 11:37

I know that CryptProtectData function crypts data using windows user\'s password, I can decrypt it using CryptUnprotectData function when I am logged in crypter user, how is

2条回答
  •  余生分开走
    2021-01-14 12:10

    CryptProtectData uses an encryption algorithm which derives its key from environment variables such as the current machine ID and user credentials. This also implies that you need to be the encrypting user to decrypt in most cases.

    There is a small caveat, however, where you can bypass the user credentials getting into the make up of the key; but sadly the best you can do is encrypt something that can be decrypted by any user on the same machine.

    As presented here, you can set the dwFlags to "CRYPTPROTECT_LOCAL_MACHINE" (dwFlags being an enum, you can simply set it to a uint 0). Just be sure to also set dwFlags to uint(0) when you call CryptUnprotectData on your encrypted stuff and the two functions will be perfectly symmetric and work fine with each other. I have personally tried this and can attest that it works.

    Yes, this whole needing the same machine system gets really annoying, but it is by far the securest way to encrypt something and be sure no other computer in the world can decrypt it.

    Hope this helped, Nashwan.

提交回复
热议问题