public class SecutityPassword:IDisposable
{
private RijndaelManaged Transformer = new RijndaelManaged();
public SecutityPassword()
{
Transformer.IV = new byte[] { 12, 23, 34, 66, 56, 67, 78, 1, 1, 5, 22, 05, 67, 23, 89, 1 };
Transformer.Key = new byte[] { 02, 58, 94, 254, 3, 3, 3, 1, 54, 65, 34, 34, 45, 65, 77, 100, 02, 58, 94, 22, 43, 3, 53, 1, 54, 65, 34, 34, 45, 65, 77, 100 };
}
public string Coding(string SourceText)
{
try
{
byte[] toCode = Encoding.ASCII.GetBytes(SourceText);
ICryptoTransform Itrans = Transformer.CreateEncryptor(Transformer.Key, Transformer.IV);
MemoryStream buffer = new MemoryStream();
CryptoStream CryptoBuffer = new CryptoStream(buffer, Itrans, CryptoStreamMode.Write);
CryptoBuffer.Write(toCode, 0, toCode.Length);
CryptoBuffer.FlushFinalBlock();
byte[] result = buffer.ToArray();
return Convert.ToBase64String(result);
}
catch (Exception)
{
return SourceText;
}
}
public string Decoding(string SourceText)
{
try
{
byte[] tmp2 = Convert.FromBase64String(SourceText);
ICryptoTransform Idec = Transformer.CreateDecryptor(Transformer.Key, Transformer.IV);
MemoryStream buffer = new MemoryStream();
CryptoStream CryptoBuffer = new CryptoStream(buffer, Idec, CryptoStreamMode.Write);
CryptoBuffer.Write(tmp2, 0, tmp2.Length);
CryptoBuffer.FlushFinalBlock();
byte[] Decripted = buffer.ToArray();
return Encoding.ASCII.GetString(Decripted);
}
catch (Exception)
{
return SourceText;
}
}
#region IDisposable Members
public void Dispose()
{
Transformer.Clear();
}
#endregion
}