简体   繁体   中英

Encrypting username/password files (app.config) and Unit Tests on Visual Studio Team Services

I have some unit tests which target some overriden app.config files. Each config file has encrypted password/username using DataProtectionConfigurationProvider via aspnet_regiis.exe

This is all fine and dandy on my local machine where they are created. Now when these are deployed and run to our Visual Studio Team Services and the build definition is run, the tests that target the encrypted credentials methods fail because:

System.Configuration.ConfigurationErrorsException: Failed to decrypt using provider 'DataProtectionConfigurationProvider'. Error message from the provider: Key not valid for use in specified state.

I appreciate that this error is caused by not running aspnet_regiis.exe on the local machine the app/tests will be running on.

My question is what is best practice here? Because even if i build a Team Service build definition which runs aspnet_regiis.exe (I presume you can do that) against an unencrypted app.config file first, I'm still storing unencrypted data online for a while.

EDIT:

The answer helped me identifier I needed to use RsaProtectedConfigurationProvider instead of DataProtectionConfigurationProvider I did alittle blog post here explaining what I did:

Encrypting credentials in app.config files

The encryption key for this uses the machine key which will differ up on the azure server to your local box. Set a machine key manually so it will always be the same in the web.config

See this article on setting your machine key.. https://technet.microsoft.com/en-gb/library/cc755177(v=ws.10).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM