Convert.ToBase64CharArray : Convert « System « C# / C Sharp by API






Convert.ToBase64CharArray

  

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 += 4 - (arrLength % 4);
      }
    
      char[] encodedCharArray = new char[arrLength];
      Convert.ToBase64CharArray(inputBytes, 0, inputBytes.Length, encodedCharArray, 0);
      
      return (new string(encodedCharArray));
    }      
}

   
    
  








Related examples in the same category

1.Convert.ChangeType
2.Convert.FromBase64CharArray
3.Convert.FromBase64String
4.Convert.ToBase64String
5.Convert.ToInt32
6.Convert.ToUInt32