public class EncryptDecryptUtil
{
public static string Decrypt(string strData)
{
if (strData.Length > 0)
return DecodeFrom64(strData);
else
return strData;
}
public static string Encrypt(string strData)
{
if (strData.Length > 0)
return EncodeBase64(strData);
else
return strData;
}
internal static string DecodeFrom64(string encodedData)
{
try
{
byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
string returnValue = System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
return returnValue;
}
catch (Exception e)
{
throw new Exception("Error in EncodeBase64" + e.Message);
}
}
internal static string EncodeBase64(string data)
{
try
{
byte[] toencode_byte = System.Text.ASCIIEncoding.ASCII.GetBytes(data);
string result = Convert.ToBase64String(toencode_byte);
return result;
}
catch (Exception e)
{
throw new Exception("Error in EncodeBase64" + e.Message);
}
}
}
{
public static string Decrypt(string strData)
{
if (strData.Length > 0)
return DecodeFrom64(strData);
else
return strData;
}
public static string Encrypt(string strData)
{
if (strData.Length > 0)
return EncodeBase64(strData);
else
return strData;
}
internal static string DecodeFrom64(string encodedData)
{
try
{
byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
string returnValue = System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
return returnValue;
}
catch (Exception e)
{
throw new Exception("Error in EncodeBase64" + e.Message);
}
}
internal static string EncodeBase64(string data)
{
try
{
byte[] toencode_byte = System.Text.ASCIIEncoding.ASCII.GetBytes(data);
string result = Convert.ToBase64String(toencode_byte);
return result;
}
catch (Exception e)
{
throw new Exception("Error in EncodeBase64" + e.Message);
}
}
}
No comments:
Post a Comment