Beispiel #1
0
Datei: AES.cs Projekt: zhgl7688/-
        /// <summary>
        /// DES¼ÓÃÜ×Ö·û´®
        /// </summary>
        /// <param name="encryptString">´ý¼ÓÃܵÄ×Ö·û´®</param>
        /// <param name="encryptKey">¼ÓÃÜÃÜÔ¿,ÒªÇóΪ8λ</param>
        /// <returns>¼ÓÃܳɹ¦·µ»Ø¼ÓÃܺóµÄ×Ö·û´®,ʧ°Ü·µ»ØÔ´´®</returns>
        public static string AESEncrypt(string encryptString, string encryptKey)
        {
            encryptKey = ZString.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));
        }
Beispiel #2
0
Datei: AES.cs Projekt: zhgl7688/-
        /// <summary>
        /// DES½âÃÜ×Ö·û´®
        /// </summary>
        /// <param name="decryptString">´ý½âÃܵÄ×Ö·û´®</param>
        /// <param name="decryptKey">½âÃÜÃÜÔ¿,ÒªÇóΪ8λ,ºÍ¼ÓÃÜÃÜÔ¿Ïàͬ</param>
        /// <returns>½âÃܳɹ¦·µ»Ø½âÃܺóµÄ×Ö·û´®,ʧ°Ü·µÔ´´®</returns>
        public static string AESDecrypt(string decryptString, string decryptKey)
        {
            try
            {
                decryptKey = ZString.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("");
            }
        }