I looked the at mono (open source .net for almost all platforms!) sources
and this is what I found:
--------------------
inside the inside the \mcs\class\corlib\System\Convert.cs :
public static string ToBase64String (byte[] inArray)
{
if (inArray == null)
throw new ArgumentNullException ("inArray");
return ToBase64String (inArray, 0, inArray.Length);
}
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));
}
inside the
\mcs\class\corlib\System.Security.Cryptography\ToBase64Transform.cs:
// Mono System.Convert depends on the ability to process multiple blocks
internal byte[] InternalTransformFinalBlock (byte[] inputBuffer, int
inputOffset, int inputCount)
{
int blockLen = this.InputBlockSize;
int outLen = this.OutputBlockSize;
int fullBlocks = inputCount / blockLen;
int tail = inputCount % blockLen;
byte[] res = new byte [(inputCount != 0)
? ((inputCount + 2) / blockLen) * outLen
: 0];
int outputOffset = 0;
for (int i = 0; i < fullBlocks; i++) {
TransformBlock (inputBuffer, inputOffset,
blockLen, res, outputOffset);
inputOffset += blockLen;
outputOffset += outLen;
}
byte[] lookup = Base64Constants.EncodeTable;
int b1,b2;
// When fewer than 24 input bits are available
// in an input group, zero bits are added
// (on the right) to form an integral number of
// 6-bit groups.
switch (tail) {
case 0:
break;
case 1:
b1 = inputBuffer [inputOffset];
res [outputOffset] = lookup [b1 >> 2];
res [outputOffset+1] = lookup [(b1 << 4) & 0x30];
// padding
res [outputOffset+2] = (byte)'=';
res [outputOffset+3] = (byte)'=';
break;
case 2:
b1 = inputBuffer [inputOffset];
b2 = inputBuffer [inputOffset + 1];
res [outputOffset] = lookup [b1 >> 2];
res [outputOffset+1] = lookup [((b1 << 4) & 0x30) | (b2 >> 4)];
res [outputOffset+2] = lookup [(b2 << 2) & 0x3c];
// one-byte padding
res [outputOffset+3] = (byte)'=';
break;
}
return res;
}
--------------------
from mono-1.1.9.1.
Ab.
http://joehacker.blogspot.com
John A Grandy said:
Oh man, I'm terrible at cpp. Is the code for Guid creation available in c#
anywhere ?