1

PowerShell can store a value securely in a file:

PS > Read-Host 'Enter password' -AsSecureString | ConvertFrom-SecureString | Out-File ~\Desktop\SerializedSecurePassword.txt

How does one deserialize the value stored in the text into a System.Security.SecureString in a C# application?

string path = @"C:\\Users\\<user>\\Desktop\\SerializedSecurePassword.txt";
string contents = File.ReadAllText(path);

System.Security.SecureString SecurePassword = ?;
craig
  • 25,664
  • 27
  • 119
  • 205
  • 1
    You can use `ConvertTo-SecureString` from C# or the [`ProtectedData.Unprotect()`](https://msdn.microsoft.com/en-us/library/xh68ketz(v=vs.110).aspx) method. The latter will require you to parse the input string manually – Mathias R. Jessen Dec 01 '16 at 23:11
  • I used the technique suggested by [this answer](https://stackoverflow.com/questions/8871337/how-can-i-encrypt-user-settings-such-as-passwords-in-my-application#8875545). – craig Dec 02 '16 at 14:23
  • I think in this case you can use "System.Security.Cryptography" and "ProtectedData.Unprotect()" method for this. – Ranadip Dutta Dec 02 '16 at 14:45
  • @craig post that as an answer then – Mathias R. Jessen Dec 05 '16 at 09:20

0 Answers0