Encrypting password in a MSBuild file

≡放荡痞女 提交于 2019-12-10 17:38:55

问题


I want to encrypt the password I am supplying in the following code:

<Target Name="Default">
    <!-- Install a service on a Remote Machine -->
    <MSBuild.ExtensionPack.Computer.WindowsService 
        TaskAction="Install" 
        ServiceName="__TestService1" 
        User="$(User)" 
        Password="$(password)"
        ServicePath="c:\WINDOWS\system32\taskmgr.exe" 
        RemoteUser="$(RemoteUser)" 
        RemoteUserPassword="$(RemoteUserPassword)" 
        MachineName="$(RemoteMachine)" />
</Target>

I dont want to hardcode the password. How can I encrypt it? Please provide your suggestion. I googled but could not find a solution which will work for me.

Thank you.


回答1:


There are many ways to do this. I describe just two simplest:

Have you thought about using feature of NTFS Encrypting File System?

Store password in a file as plaintext and mark file as encrypted. Then only user created file (by default) has an access to file (if you are more paranoid you can restrict access by proper setting ACL for given password file). Then you can easily read password by

<ReadLinesFromFile File="$(PasswordFile)" >
  <Output TaskParameter="Lines" ItemName="Password"/>
</ReadLinesFromFile>

Other possibility is to store password in registry (HKLM, or HKCU), set up permission to selected user on a key. You can easily read registry values

In order to prevent directly read password from ntuser.dat (registry storage – you can encrypt password by inline task for example this way http://msdn.microsoft.com/en-us/library/ff649224.aspx)



来源:https://stackoverflow.com/questions/16662100/encrypting-password-in-a-msbuild-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!