public static string ToBase64String (byte[] inArray, int offset, int length)
{
if (inArray == null)
throw new ArgumentNullException ("inArray");
if (offset < 0 || length < 0)
throw new ArgumentOutOfRangeException ("offset < 0 || length < 0");
// avoid integer overflow
if (offset > inArray.Length - length)
throw new ArgumentOutOfRangeException ("offset + length > array.Length");
// note: normally ToBase64Transform doesn't support multiple block processing
byte[] outArr = ToBase64Transform.InternalTransformFinalBlock (inArray, offset, length);
return (new ASCIIEncoding ().GetString (outArr));
}