Esempio n. 1
0
        public static byte[] DecryptAes(this byte[] @this)
        {
            var data = @this.FastClone();

            using (var aes = new RijndaelManaged())
            {
                aes.Mode      = CipherMode.CFB;
                aes.Padding   = PaddingMode.None;
                aes.KeySize   = 192;
                aes.BlockSize = 128;
                aes.GenerateKeys(data.Length);

                var blockSize  = aes.BlockSize / 8;
                var needChange = data.Length % blockSize != 0;
                var diff       = blockSize - data.Length % blockSize;
                if (needChange)
                {
                    Array.Resize(ref data, data.Length + diff);
                }

                data = aes.Decrypt(data);

                if (needChange)
                {
                    Array.Resize(ref data, data.Length - diff);
                }
                return(data);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="str">要解密的 string 字符串</param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string Decrypt(this RijndaelManaged manager, string str, Encoding encoding = null)
        {
            byte[] stringArray = Convert.FromBase64String(str);

            byte[] result = manager.Decrypt(stringArray);

            return((encoding ?? DefaultEncoding).GetString(result));
        }
        public void TestRijndaelAlgorithm()
        {
            var provider = new RijndaelManaged();

            provider.Key     = new Byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
            provider.IV      = new Byte[] { 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 };
            provider.Padding = PaddingMode.Zeros;
            provider.Mode    = CipherMode.CBC;

            var encodedData = provider.Encrypt(_clearData);
            var decodedData = provider.Decrypt(encodedData);

            CollectionAssert.AreEqual(_clearData, decodedData);
        }
Esempio n. 4
0
        public static byte[] DecryptAES(byte[] data)
        {
            using (var aes = new RijndaelManaged())
            {
                aes.Mode      = CipherMode.CFB;
                aes.Padding   = PaddingMode.Zeros;
                aes.KeySize   = 192;
                aes.BlockSize = 128;
                aes.GenerateKeys(data.Length);

                Array.Resize(ref data, data.Length + 16 - data.Length % 16);

                return(aes.Decrypt(data));
            }
        }