System.Security.Cryptography.FromBase64Transform.TransformBlock C# (CSharp) Метод

TransformBlock() публичный Метод

public TransformBlock ( byte inputBuffer, int inputOffset, int inputCount, byte outputBuffer, int outputOffset ) : int
inputBuffer byte
inputOffset int
inputCount int
outputBuffer byte
outputOffset int
Результат int
        public int TransformBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset)
        {
            ValidateTransformBlock(inputBuffer, inputOffset, inputCount);
            if (_inputBuffer == null) throw new ObjectDisposedException(null, SR.ObjectDisposed_Generic);

            int effectiveCount;
            byte[] temp = GetTempBuffer(inputBuffer, inputOffset, inputCount, out effectiveCount);

            if (effectiveCount + _inputIndex < 4)
            {
                Buffer.BlockCopy(temp, 0, _inputBuffer, _inputIndex, effectiveCount);
                _inputIndex += effectiveCount;
                return 0;
            }

            byte[] result = ConvertFromBase64(temp, effectiveCount);

            Buffer.BlockCopy(result, 0, outputBuffer, outputOffset, result.Length);

            return result.Length;
        }

Usage Example

Пример #1
0
	    /// <summary>
	    /// Decodes a base64 encoded string into the bytes it describes
	    /// </summary>
	    /// <param name="base64Encoded">The string to decode</param>
	    /// <returns>A byte array that the base64 string described</returns>
	    public static byte[] Decode(string base64Encoded)
	    {
	        using (var memoryStream = new MemoryStream())
	        {
	            base64Encoded = base64Encoded.Replace("\r\n", "");
	            base64Encoded = base64Encoded.Replace("\t", "");
	            base64Encoded = base64Encoded.Replace(" ", "");

	            var inputBytes = Encoding.ASCII.GetBytes(base64Encoded);

	            using (var transform = new FromBase64Transform(FromBase64TransformMode.DoNotIgnoreWhiteSpaces))
	            {
	                var outputBytes = new byte[transform.OutputBlockSize];

	                // Transform the data in chunks the size of InputBlockSize.
	                const int inputBlockSize = 4;
	                var currentOffset = 0;
	                while (inputBytes.Length - currentOffset > inputBlockSize)
	                {
	                    transform.TransformBlock(inputBytes, currentOffset, inputBlockSize, outputBytes, 0);
	                    currentOffset += inputBlockSize;
	                    memoryStream.Write(outputBytes, 0, transform.OutputBlockSize);
	                }

	                // Transform the final block of data.
	                outputBytes = transform.TransformFinalBlock(inputBytes, currentOffset,
	                    inputBytes.Length - currentOffset);
	                memoryStream.Write(outputBytes, 0, outputBytes.Length);
	            }

	            return memoryStream.ToArray();
	        }
	    }
All Usage Examples Of System.Security.Cryptography.FromBase64Transform::TransformBlock