You are not Logged in
Would you like to Login or Register

Today is: Friday, 21 November, 2008
Check this months hot topics

Encoding string to Base64 / UTF8

Sometimes you need to convert strings to Base64, for example in security components. The function below does this:

public string stringToBase64(string s)
{
    try
    {
        byte[] bytes = new byte[s.Length];
        bytes = System.Text.Encoding.UTF8.GetBytes(s);
        return Convert.ToBase64String(bytes);
    }
    catch (Exception e)
    {
        throw new Exception("stringToBase64 error: " + e.Message);
    }
}
kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Dave Howard Skype
Author : Dave Howard
Published : Tuesday, 05 September, 2006

I have been involved in IT development for the last 10 years - a lot of it around desktop applications and telecoms.

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views