Пример #1
0
 /// <summary>
 /// Decode the Base64-encoded data in input and return the data in
 /// a new byte array.
 /// </summary>
 /// <remarks>
 /// Decode the Base64-encoded data in input and return the data in
 /// a new byte array.
 /// <p>The padding '=' characters at the end are considered optional, but
 /// if any are present, there must be the correct number of them.
 /// </remarks>
 /// <param name="input">the data to decode</param>
 /// <param name="offset">the position within the input array at which to start</param>
 /// <param name="len">the number of bytes of input to decode</param>
 /// <param name="flags">
 /// controls certain features of the decoded output.
 /// Pass
 /// <code>DEFAULT</code>
 /// to decode standard Base64.
 /// </param>
 /// <exception cref="System.ArgumentException">
 /// if the input contains
 /// incorrect padding
 /// </exception>
 public static byte[] Decode(byte[] input, int offset, int len, int flags)
 {
     // Allocate space for the most data the input could represent.
     // (It could contain less if it contains whitespace, etc.)
     Base64.Decoder decoder = new Base64.Decoder(flags, new byte[len * 3 / 4]);
     if (!decoder.Process(input, offset, len, true))
     {
         throw new ArgumentException("bad base-64");
     }
     // Maybe we got lucky and allocated exactly enough output space.
     if (decoder.op == decoder.output.Length)
     {
         return(decoder.output);
     }
     // Need to shorten the array, so allocate a new one of the
     // right size and copy.
     byte[] temp = new byte[decoder.op];
     System.Array.Copy(decoder.output, 0, temp, 0, decoder.op);
     return(temp);
 }
Пример #2
0
		/// <summary>
		/// Decode the Base64-encoded data in input and return the data in
		/// a new byte array.
		/// </summary>
		/// <remarks>
		/// Decode the Base64-encoded data in input and return the data in
		/// a new byte array.
		/// <p>The padding '=' characters at the end are considered optional, but
		/// if any are present, there must be the correct number of them.
		/// </remarks>
		/// <param name="input">the data to decode</param>
		/// <param name="offset">the position within the input array at which to start</param>
		/// <param name="len">the number of bytes of input to decode</param>
		/// <param name="flags">
		/// controls certain features of the decoded output.
		/// Pass
		/// <code>DEFAULT</code>
		/// to decode standard Base64.
		/// </param>
		/// <exception cref="System.ArgumentException">
		/// if the input contains
		/// incorrect padding
		/// </exception>
		public static byte[] Decode(byte[] input, int offset, int len, int flags)
		{
			// Allocate space for the most data the input could represent.
			// (It could contain less if it contains whitespace, etc.)
			Base64.Decoder decoder = new Base64.Decoder(flags, new byte[len * 3 / 4]);
			if (!decoder.Process(input, offset, len, true))
			{
				throw new ArgumentException("bad base-64");
			}
			// Maybe we got lucky and allocated exactly enough output space.
			if (decoder.op == decoder.output.Length)
			{
				return decoder.output;
			}
			// Need to shorten the array, so allocate a new one of the
			// right size and copy.
			byte[] temp = new byte[decoder.op];
			System.Array.Copy(decoder.output, 0, temp, 0, decoder.op);
			return temp;
		}