/*
Used to store passwords in config file.
*/
using System;
using System.Text;
namespace SmartClient
{
///
/// Encrypt / decrypt string using base64.
///
public class SimpleEncrypt
{
private SimpleEncrypt()
{
}
///
/// Return base64 version of string.
///
public static string Encrypt(string text)
{
try
{
byte[] bytes = Encoding.ASCII.GetBytes(text);
return Convert.ToBase64String(bytes, 0, bytes.Length);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
return String.Empty;
}
}
///
/// Return string version of base64 string.
///
public static string Decrypt(string text)
{
try
{
byte[] bytes = Convert.FromBase64String(text);
return Encoding.ASCII.GetString(bytes, 0, bytes.Length);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
return String.Empty;
}
}
}
}
|