Created
January 30, 2015 13:41
-
-
Save lennybacon/94189f470f2f25a4defd to your computer and use it in GitHub Desktop.
Using credentials based secure string that is disposed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using System.Linq; | |
using System.Net; | |
using System.Security; | |
using NUnit.Framework; | |
namespace Tests | |
{ | |
[TestFixture] | |
public class SecureStringTests | |
{ | |
[Test] | |
public void Should_use_credientials_created_with_secure_string_after_it_is_disposed() | |
{ | |
ICredentials credentials; | |
var password = "$ome53cure1"; | |
using (var secure = | |
password.Aggregate( | |
new SecureString(), | |
(ss, c) => { ss.AppendChar(c); return ss; } | |
) | |
) | |
{ | |
credentials = new NetworkCredential("John.Doe", secure, "MyDomain"); | |
} | |
var wc = new WebClient { Credentials = credentials }; | |
var result = wc.DownloadString("https://...."); | |
Trace.Write(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment