Skip to content

Instantly share code, notes, and snippets.

@lennybacon
Created January 30, 2015 13:41
Show Gist options
  • Save lennybacon/94189f470f2f25a4defd to your computer and use it in GitHub Desktop.
Save lennybacon/94189f470f2f25a4defd to your computer and use it in GitHub Desktop.
Using credentials based secure string that is disposed
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