4

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.

SharpCoder
  • 18,279
  • 43
  • 153
  • 249
  • You should clarify your question. Are you looking for a generic command line tool to encrypt a password string, or are you looking for a way to encrypt the value of a build property at build time? – Owen Wengerd May 23 '13 at 04:07
  • @OwenWengerd : Thank you for reply. I do not want to store password as plain text. The idea is to encrypt it and when the same is passed as a parameter in the build script, the same should be decrypted. – SharpCoder May 23 '13 at 04:43

1 Answers1

2

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)

Palo Misik
  • 741
  • 3
  • 7