Example #1
0
File: AES.cs Project: zeje/AAA
        /// <summary>DES¼ÓÃÜ×Ö·û´®
        /// </summary>
        /// <param name="encryptString">´ý¼ÓÃܵÄ×Ö·û´®</param>
        /// <param name="encryptKey">¼ÓÃÜÃÜÔ¿,ÒªÇóΪ8λ</param>
        /// <returns>¼ÓÃܳɹ¦·µ»Ø¼ÓÃܺóµÄ×Ö·û´®,ʧ°Ü·µ»ØÔ´´®</returns>
        public static string AESEncrypt(string encryptString, string encryptKey)
        {
            encryptKey = String_.GetSubString(encryptKey, 32, "");
            encryptKey = encryptKey.PadRight(32, ' ');

            RijndaelManaged rijndaelProvider = new RijndaelManaged();

            rijndaelProvider.Key = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 32));
            rijndaelProvider.IV  = AESKeys;
            ICryptoTransform rijndaelEncrypt = rijndaelProvider.CreateEncryptor();

            byte[] inputData     = Encoding.UTF8.GetBytes(encryptString);
            byte[] encryptedData = rijndaelEncrypt.TransformFinalBlock(inputData, 0, inputData.Length);

            return(Convert.ToBase64String(encryptedData));
        }
Example #2
0
File: AES.cs Project: zeje/AAA
        /// <summary>DES½âÃÜ×Ö·û´®
        /// </summary>
        /// <param name="decryptString">´ý½âÃܵÄ×Ö·û´®</param>
        /// <param name="decryptKey">½âÃÜÃÜÔ¿,ÒªÇóΪ8λ,ºÍ¼ÓÃÜÃÜÔ¿Ïàͬ</param>
        /// <returns>½âÃܳɹ¦·µ»Ø½âÃܺóµÄ×Ö·û´®,ʧ°Ü·µÔ´´®</returns>
        public static string AESDecrypt(string decryptString, string decryptKey)
        {
            try
            {
                decryptKey = String_.GetSubString(decryptKey, 32, "");
                decryptKey = decryptKey.PadRight(32, ' ');

                RijndaelManaged rijndaelProvider = new RijndaelManaged();
                rijndaelProvider.Key = Encoding.UTF8.GetBytes(decryptKey);
                rijndaelProvider.IV  = AESKeys;
                ICryptoTransform rijndaelDecrypt = rijndaelProvider.CreateDecryptor();

                byte[] inputData     = Convert.FromBase64String(decryptString);
                byte[] decryptedData = rijndaelDecrypt.TransformFinalBlock(inputData, 0, inputData.Length);

                return(Encoding.UTF8.GetString(decryptedData));
            }
            catch
            {
                return("");
            }
        }