コード例 #1
0
        internal static byte[] InternalTransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount)
        {
            int num  = 3;
            int num2 = 4;
            int num3 = inputCount / num;
            int num4 = inputCount % num;

            byte[] array = new byte[(inputCount == 0) ? 0 : ((inputCount + 2) / num * num2)];
            int    num5  = 0;

            for (int i = 0; i < num3; i++)
            {
                ToBase64Transform.InternalTransformBlock(inputBuffer, inputOffset, num, array, num5);
                inputOffset += num;
                num5        += num2;
            }
            byte[] encodeTable = Base64Constants.EncodeTable;
            switch (num4)
            {
            case 1:
            {
                int num6 = (int)inputBuffer[inputOffset];
                array[num5]     = encodeTable[num6 >> 2];
                array[num5 + 1] = encodeTable[num6 << 4 & 48];
                array[num5 + 2] = 61;
                array[num5 + 3] = 61;
                break;
            }

            case 2:
            {
                int num6 = (int)inputBuffer[inputOffset];
                int num7 = (int)inputBuffer[inputOffset + 1];
                array[num5]     = encodeTable[num6 >> 2];
                array[num5 + 1] = encodeTable[(num6 << 4 & 48) | num7 >> 4];
                array[num5 + 2] = encodeTable[num7 << 2 & 60];
                array[num5 + 3] = 61;
                break;
            }
            }
            return(array);
        }
コード例 #2
0
 /// <summary>Converts the specified region of the input byte array to base 64 and copies the result to the specified region of the output byte array.</summary>
 /// <returns>The number of bytes written.</returns>
 /// <param name="inputBuffer">The input to compute to base 64. </param>
 /// <param name="inputOffset">The offset into the input byte array from which to begin using data. </param>
 /// <param name="inputCount">The number of bytes in the input byte array to use as data. </param>
 /// <param name="outputBuffer">The output to which to write the result. </param>
 /// <param name="outputOffset">The offset into the output byte array from which to begin writing data. </param>
 /// <exception cref="T:System.ObjectDisposedException">The current <see cref="T:System.Security.Cryptography.ToBase64Transform" /> object has already been disposed. </exception>
 /// <exception cref="T:System.Security.Cryptography.CryptographicException">The data size is not valid. </exception>
 /// <exception cref="T:System.ArgumentException">The <paramref name="inputBuffer" /> parameter contains an invalid offset length.-or-The <paramref name="inputCount" /> parameter contains an invalid value.</exception>
 /// <exception cref="T:System.ArgumentNullException">The <paramref name="inputBuffer" /> parameter is null.</exception>
 /// <exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="inputBuffer" /> parameter requires a non-negative number.</exception>
 public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
 {
     if (this.m_disposed)
     {
         throw new ObjectDisposedException("TransformBlock");
     }
     if (inputBuffer == null)
     {
         throw new ArgumentNullException("inputBuffer");
     }
     if (outputBuffer == null)
     {
         throw new ArgumentNullException("outputBuffer");
     }
     if (inputCount < 0)
     {
         throw new ArgumentException("inputCount", "< 0");
     }
     if (inputCount > inputBuffer.Length)
     {
         throw new ArgumentException("inputCount", Locale.GetText("Overflow"));
     }
     if (inputOffset < 0)
     {
         throw new ArgumentOutOfRangeException("inputOffset", "< 0");
     }
     if (inputOffset > inputBuffer.Length - inputCount)
     {
         throw new ArgumentException("inputOffset", Locale.GetText("Overflow"));
     }
     if (outputOffset < 0)
     {
         throw new ArgumentOutOfRangeException("outputOffset", "< 0");
     }
     if (outputOffset > outputBuffer.Length - inputCount)
     {
         throw new ArgumentException("outputOffset", Locale.GetText("Overflow"));
     }
     ToBase64Transform.InternalTransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
     return(this.OutputBlockSize);
 }