///
/// Encodes the input value to a Base64 string using the default encoding.
///
/// The input value.
/// The Base 64 encoded string
public static string EncodeBase64(this string value)
{
return value.EncodeBase64(null);
}
///
/// Encodes the input value to a Base64 string using the supplied encoding.
///
/// The input value.
/// The encoding.
/// The Base 64 encoded string
public static string EncodeBase64(this string value, Encoding encoding)
{
encoding = (encoding ?? Encoding.UTF8);
var bytes = encoding.GetBytes(value);
return Convert.ToBase64String(bytes);
}
///
/// Decodes a Base 64 encoded value to a string using the default encoding.
///
/// The Base 64 encoded value.
/// The decoded string
public static string DecodeBase64(this string encodedValue)
{
return encodedValue.DecodeBase64(null);
}
///
/// Decodes a Base 64 encoded value to a string using the supplied encoding.
///
/// The Base 64 encoded value.
/// The encoding.
/// The decoded string
public static string DecodeBase64(this string encodedValue, Encoding encoding)
{
encoding = (encoding ?? Encoding.UTF8);
var bytes = Convert.FromBase64String(encodedValue);
return encoding.GetString(bytes);
}
|