• C# ASE加密解密


    项目中比较常用的加密手段

       /// <summary>
        /// ASE_128_ECB_无填充_64Base_加密函数
        /// </summary>
        /// <param name="content">要加密的内容</param>
        /// <param name="key">一定要16位的密钥</param>
        /// <returns>加密的字符串(字节)</returns>
        public static byte[] Func_AES128加密(string content, string key)
        {
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(content);
    
            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.PKCS7;
    
            ICryptoTransform cTransform = rDel.CreateEncryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
    
            //返回字节数组,可用Convert.FromBase64String()转换为字节
            //return Convert.ToBase64String(resultArray, 0, resultArray.Length);    
    
            return resultArray;
        }
    
    
    
    
    
        /// <summary>
        ///  ASE_128_ECB_无填充_64Base_解密函数
        /// </summary>
        /// <param name="content">密串(字节)</param>
        /// <param name="keyArray">密钥(字节)</param>
        /// <returns>解密后的字符串</returns>
        public static byte[] Func_AES128解密(byte[] content, byte[] keyArray)
        #region
        {
    
            RijndaelManaged rDel = new RijndaelManaged();
            rDel.Key = keyArray;
            rDel.Mode = CipherMode.ECB;
            rDel.Padding = PaddingMode.None;
            rDel.BlockSize = 128;
    
            ICryptoTransform cTransform = rDel.CreateDecryptor();
            byte[] resultArray = cTransform.TransformFinalBlock(content, 0, content.Length);
    
            return resultArray;
    
        }
        #endregion
    
    
    
    
    
    使用:
    
           byte[] _val1 = Func_AES128加密("Lee", "abcdef1234567890");
    
            byte[] _key = Encoding.UTF8.GetBytes("abcdef1234567890");
            
            byte[] _return1 = Func_AES128解密(_val1, _key);
    
            TextBox2.Text = Encoding.UTF8.GetString(_return1);
  • 相关阅读:
    JS面试题(一)
    cookie、locakstorage、sessionstorage的区别
    BOM操作
    DOM表单(复选框)
    DOM表格操作
    Javascript的组成——EMACScript、DOM、BOM
    scrollto 到指定位置
    编写一个javscript函数 fn,该函数有一个参数 n(数字类型),其返回值是一个数组,该数组内是 n 个随机且不重复的整数,且整数取值范围是 [2, 32]。
    使用bluebird解决promise兼容性问题
    Mac 更改/usr/bin 目录权限失败
  • 原文地址:https://www.cnblogs.com/CyLee/p/5421290.html
Copyright © 2020-2023  润新知