dlwyatt / ProtectedData

PowerShell Module for securely encrypting and sharing secret data such as passwords.
Apache License 2.0
77 stars 16 forks source link

Need help making it work, it seems #12

Closed SylvainMartel closed 9 years ago

SylvainMartel commented 9 years ago

Hi, I'm the one who asked a question on https://gallery.technet.microsoft.com/PowerShell-Encryption-45709b87 :-)

I started using this function since you mentioned it's working with v3 certificate, but I'm still having trouble with the decryption failing.

2 questions: First: is loading Security.Cryptography.dll obligatory? Because it refuse to load with the error Could not load file or assembly 'file:///C:\Temp\test\Security.Cryptography.dll' or one of its dependencies. (0x80131515)

But if I comment that line out and go on without loading it, I can encrypt a string using a certificate just fine, but the decryption always fails (thus the second question, why is it still failing...?) The error message is ValidateKeyEncryptionCertificate : Could not find private key for certificate 'F4E03D8E9B14E7205074EDFA8156FE8C20948F74'. But that's the right thumbprint for the certificate, and that certificate does have a private key. As mentionned on the other website, it's created using New-SelfSignedCertificate

dlwyatt commented 9 years ago

Security.Cryptography.dll is necessary for CNG support (which is exactly what you need for V3 certificates.)

Depending on how you downloaded the module, you may need to run Unblock-File on the DLL in order to get it working. (Unblock-File is a PowerShell v3+ command.).

SylvainMartel commented 9 years ago

Thanks, that was indeed the problem. I had acutally unblocked it, but I forgot to close and restard Powershell ISE, so it kept the unblock version in memory, grrr.

It's all working now, big thanks, this function is a life saver for our automated deployment that require passwords!

dlwyatt commented 9 years ago

No problem, glad to help! :)