|
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml.Serialization;
using Mullivan.Serialization;
using Mullivan.Cryptography;
namespace Mullivan.Security
{
public class SerializableCredential : IXmlSerializable
{
private string _userName = string.Empty;
private string _password = string.Empty;
private string _domain = string.Empty;
private const string _INITVECT = "noau8g348OIF@E*00(_!)@(*#&$303";
private const string _ENCKEY = "alkjsd*(@()*_)(*$poqawjqIH@IUH";
public string UserName
{
get
{
return _userName;
}
set
{
_userName = value;
}
}
public string Password
{
get
{
return _password;
}
set
{
_password = value;
}
}
public string Domain
{
get
{
return _domain;
}
set
{
_domain = value;
}
}
public NetworkCredential GetCredential()
{
return new NetworkCredential(this.UserName, this.Password, this.Domain);
}
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
if (reader.IsEmptyElement)
return;
reader.ReadStartElement();
reader.ReadStartElement("UserName");
_userName = GenericSerializer.Deserialize<string>(reader);
reader.ReadEndElement();
reader.ReadStartElement("Password");
_password = Encryption.Decrypt(GenericSerializer.Deserialize<string>(reader), _INITVECT, _ENCKEY);
reader.ReadEndElement();
reader.ReadStartElement("Domain");
_domain = GenericSerializer.Deserialize<string>(reader);
reader.ReadEndElement();
reader.ReadEndElement();
}
public void WriteXml(System.Xml.XmlWriter writer)
{
writer.WriteStartElement("UserName");
GenericSerializer.Serialize<string>(_userName);
writer.WriteEndElement();
writer.WriteStartElement("Password");
GenericSerializer.Serialize<string>(Encryption.Encrypt(_password,_INITVECT, _ENCKEY));
writer.WriteEndElement();
writer.WriteStartElement("Domain");
GenericSerializer.Serialize<string>(_domain);
writer.WriteEndElement();
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.