Encrypting password in a MSBuild file

2019-06-27 19:43发布

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条回答
爷的心禁止访问
2楼-- · 2019-06-27 20:08

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)

查看更多
登录 后发表回答