.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Decoding a Base64-encoded Binary

Posted By:SanthoshNathan       Posted Date: November 01, 2010    Points: 15    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Decoding a Base64-encoded Binary
 

using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Text;
class Class1{
        static void Main(string[] args){
             Console.WriteLine(Base64EncodeBytes(new byte[5] {45,34,23,54,38}));
         }
    public static string Base64EncodeBytes(byte[] inputBytes
    {
      // Each 3 byte sequence in inputBytes must be converted to a 4 byte sequence 
      long arrLength = (long)(4.0d * inputBytes.Length / 3.0d);
      if ((arrLength  % 4!= 0
      {
        // increment the array lenght to the next multiple of 4 if it is not already divisible by 4
        arrLength += (arrLength % 4);
      }
    
      char[] encodedCharArray = new char[arrLength];
      Convert.ToBase64CharArray(inputBytes, 0, inputBytes.Length, encodedCharArray, 0);
      
      return (new string(encodedCharArray));
    }      
}

           

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend