• C#.NET AES ECB 加密


    加密:

    /// <summary>
            /// 加密
            /// </summary>
            /// <param name="content">要加密的串</param>
            /// <param name="aesKey">密钥</param>
            /// <returns></returns>
            public static string AesEncryptECB(string content, string aesKey)
            {
                byte[] byteKEY = Encoding.UTF8.GetBytes(aesKey);
    
                byte[] byteContnet = Encoding.UTF8.GetBytes(content);
    
                var _aes = new RijndaelManaged();
                _aes.Padding = PaddingMode.PKCS7;
                _aes.Mode = CipherMode.ECB;
                _aes.Key = byteKEY;
    
                var _crypto = _aes.CreateEncryptor();
                byte[] decrypted = _crypto.TransformFinalBlock(byteContnet, 0, byteContnet.Length);
    
                _crypto.Dispose();
    
                return Convert.ToBase64String(decrypted);
            }

    解密:

    /// <summary>
            /// 解密
            /// </summary>
            /// <param name="decryptStr">要解密的串</param>
            /// <param name="aesKey">密钥</param>        
            /// <returns></returns>
            public static string AesDecryptECB(string decryptStr, string aesKey)
            {
                byte[] byteKEY = Encoding.UTF8.GetBytes(aesKey);
                byte[] byteDecrypt = System.Convert.FromBase64String(decryptStr);
    
                var _aes = new RijndaelManaged();
                _aes.Padding = PaddingMode.PKCS7;
                _aes.Mode = CipherMode.ECB;
                _aes.Key = byteKEY;
    
                var _crypto = _aes.CreateDecryptor();
                byte[] decrypted = _crypto.TransformFinalBlock(byteDecrypt, 0, byteDecrypt.Length);
    
                _crypto.Dispose();
    
                return Encoding.UTF8.GetString(decrypted);
            }

    -

  • 相关阅读:
    面向过程思想理解:
    Ajax的get请求向服务器请求数据五步骤?
    什么是Ajax无刷新技术?
    Ajax和JavaScript的区别
    为什么要用ajax
    好文章分享
    easyui系列之表单二Combogrid,Form,filebox,CheckBox(3)
    属性vs字段的关系
    jQuery-Load方法
    .Net 百度经纬度转高德
  • 原文地址:https://www.cnblogs.com/runliuv/p/14124427.html
Copyright © 2020-2023  润新知