1

I'm creating this tool in C# that would take a .gpg file and decrypt it using Windows CNG. I get a .gpg file as my input parameter and it is encrypted with my key using WinPT. Decrypting it works with the tool and I can also decrypt using BouncyCastle and my secret key. The receiving party of the file will always have the rights / key to decrypt it (this is an assumption). We do not want to use the secret key anymore, but would instead like to use the key from Windows CNG store OR the ProtectedData class (preferably). The thing we would like to avoid is sharing the secret key.

I've checked this post, where it more or less explains how the encryption and decryption works using Unprotect and Protect, but i cannot get it working when the input file is a .gpg. It does work with byte arrays, and converting the .gpg data to a byte array does not help either.

Link: Pgp Private key storage on windows server advice

Is it even possible to decrypt a .gpg using this method?

Example scenario:

Let's say the file gets encrypted by John using WinPT on his laptop. He then uploads it to a folder on some server. When he downloads a tool, the proper encrypted file he previous uploaded also gets downloaded. He does not have the secret key on the PC he is currently on, at least not exported. So it should be saved somewhere in the machine registry/container, it is visible in WinPT. Is it possible to decrypt the file without the secret key exported? So that the c# program would know what key to take from the windows key store and decrypt it that way. TL;DR: Encrypt with WinPT, decrypt with ProtectedData / CNG

  • 1
    Are you trying to protect the secret used to decrypt the file, or trying to decrypt the gpg file itself using CNG or DPAPI? If the former it's certainly possible using standard key protection, but if the latter it's not possible. – Steve Mar 26 at 16:18
1

I've solved the issue by calling gpg.exe with arguments, which automatically chooses the correct key from the keyring.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.