Esempio n. 1
0
        public void InvalidInput_FromBase64Transform()
        {
            byte[] data_4bytes = Text.Encoding.ASCII.GetBytes("aaaa");

            ICryptoTransform transform = new FromBase64Transform();
            InvalidInput_Base64Transform(transform);

            // These exceptions only thrown in FromBase
            transform.Dispose();
            Assert.Throws<ObjectDisposedException>(() => transform.TransformBlock(data_4bytes, 0, 4, null, 0));
            Assert.Throws<ObjectDisposedException>(() => transform.TransformFinalBlock(Array.Empty<byte>(), 0, 0));
        }
Esempio n. 2
0
        public void InvalidInput_FromBase64Transform()
        {
            byte[] data_4bytes = Text.Encoding.ASCII.GetBytes("aaaa");

            ICryptoTransform transform = new FromBase64Transform();

            InvalidInput_Base64Transform(transform);

            // These exceptions only thrown in FromBase
            transform.Dispose();
            Assert.Throws <ObjectDisposedException>(() => transform.TransformBlock(data_4bytes, 0, 4, null, 0));
            Assert.Throws <ObjectDisposedException>(() => transform.TransformFinalBlock(Array.Empty <byte>(), 0, 0));
        }
Esempio n. 3
0
        public void InvalidInput_FromBase64Transform()
        {
            byte[]           data_4bytes = Text.Encoding.ASCII.GetBytes("aaaa");
            ICryptoTransform transform   = new FromBase64Transform();

            AssertExtensions.Throws <ArgumentNullException>("inputBuffer", () => transform.TransformBlock(null, 0, 0, null, 0));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("inputOffset", () => transform.TransformBlock(Array.Empty <byte>(), -1, 0, null, 0));
            AssertExtensions.Throws <ArgumentNullException>("outputBuffer", () => transform.TransformBlock(data_4bytes, 0, 4, null, 0));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("inputCount", () => transform.TransformBlock(Array.Empty <byte>(), 0, 1, null, 0));
            AssertExtensions.Throws <ArgumentException>(null, () => transform.TransformBlock(Array.Empty <byte>(), 1, 0, null, 0));

            AssertExtensions.Throws <ArgumentNullException>("inputBuffer", () => transform.TransformFinalBlock(null, 0, 0));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("inputOffset", () => transform.TransformFinalBlock(Array.Empty <byte>(), -1, 0));
            AssertExtensions.Throws <ArgumentOutOfRangeException>("inputOffset", () => transform.TransformFinalBlock(Array.Empty <byte>(), -1, 0));
            AssertExtensions.Throws <ArgumentException>(null, () => transform.TransformFinalBlock(Array.Empty <byte>(), 1, 0));

            // These exceptions only thrown in FromBase
            transform.Dispose();
            Assert.Throws <ObjectDisposedException>(() => transform.TransformBlock(data_4bytes, 0, 4, null, 0));
            Assert.Throws <ObjectDisposedException>(() => transform.TransformFinalBlock(Array.Empty <byte>(), 0, 0));
        }
Esempio n. 4
0
        //原始base64解码
        public static byte[] Base64Decode(byte[] source)
        {
            if ((source == null) || (source.Length == 0))
            {
                throw new ArgumentException("source is not valid");
            }
            FromBase64Transform fb64 = null;
            MemoryStream        stm  = null;

            try
            {
                fb64 = new FromBase64Transform();
                stm  = new MemoryStream();
                int    pos = 0;
                byte[] buff;

                while (pos + 4 < source.Length)
                {
                    buff = fb64.TransformFinalBlock(source, pos, 4);
                    stm.Write(buff, 0, buff.Length);
                    pos += 4;
                }

                buff = fb64.TransformFinalBlock(source, pos, source.Length - pos);
                stm.Write(buff, 0, buff.Length);
                return(stm.ToArray());
            }
            finally
            {
                if (fb64 != null)
                {
                    fb64.Dispose();
                }
                if (stm != null)
                {
                    stm.Dispose();
                }
            }
        }