• AES-128-CBC加密


    C#:

     public static string AesKey = "sgg45747ss223455";
    
            /// <summary>
            /// AES加密 (128-CBC加密模式)
            /// </summary>
            /// <param name="toEncrypt">内容</param>
            /// <param name="key">秘钥</param>
            /// <returns></returns>
    
            public static string Encrypt(string toEncrypt, string key)
            {
                byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
    
                byte[] ivArray = UTF8Encoding.UTF8.GetBytes(key);
                byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);
                RijndaelManaged rDel = new RijndaelManaged();
                rDel.Key = keyArray;
                rDel.IV = ivArray;
                rDel.Mode = CipherMode.CBC;
                rDel.Padding = PaddingMode.PKCS7;
                ICryptoTransform cTransform = rDel.CreateEncryptor();
                byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                return Convert.ToBase64String(resultArray, 0, resultArray.Length);
            }
            /// <summary>
            /// AES解密(128-CBC加密模式)
            /// </summary>
            /// <param name="toDecrypt">密文</param>
            /// <param name="key">秘钥(Base64String)</param>
            /// <returns></returns>
            public static string Decrypt(string toDecrypt, string key)
            {
                byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);
                byte[] ivArray = UTF8Encoding.UTF8.GetBytes(key);
    
                byte[] toEncryptArray = Convert.FromBase64String(toDecrypt);
                RijndaelManaged rDel = new RijndaelManaged();
                rDel.Key = keyArray;
                rDel.IV = ivArray;
                rDel.Mode = CipherMode.CBC;
                rDel.Padding = PaddingMode.PKCS7;
                ICryptoTransform cTransform = rDel.CreateDecryptor();
                byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                return UTF8Encoding.UTF8.GetString(resultArray);
            }

    PHP

  • 相关阅读:
    SpringSecurity配置
    SpringBoot整合Mybatis
    springboot整合JDBC
    SpringBoot的WEB流程
    List&TreeSet实现斗地主发牌及牌序
    SpringBoot第一个程序
    项目错误总结2021.4.21
    Spring整合Mybatis
    学习——构建民航业知识图谱并实现语义查询的
    新闻文本分类——词云可视化
  • 原文地址:https://www.cnblogs.com/siyunianhua/p/8136017.html
Copyright © 2020-2023  润新知