• c#对输入的字符串加密


     #region ========MD5加密========
        public  string  MD5Encryption(string userPassword)
        {
            string MD5EncrypPassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(userPassword, "MD5");//202CB962AC59075B964B07152D234B70
            return MD5EncrypPassword;

        }
        #endregion
        #region ========SHA1加密========
        public string SHA1Encryption(string userPassword)
        {
            string SHA1EncrypPassword = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(userPassword, "SHA1");


             return SHA1EncrypPassword;
        }
        #endregion
        #region ========DES加密========
        public string DESEncryption(string userPassword,byte[] Key,byte[] Iv)
        {
            Byte[] password = Encoding.ASCII.GetBytes(userPassword);
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            MemoryStream ms = new MemoryStream();
            ICryptoTransform iCryrt = des.CreateEncryptor(Key, Iv);
            CryptoStream cs = new CryptoStream(ms, iCryrt, CryptoStreamMode.Write);
            cs.Write(password, 0, userPassword.Length);
            cs.FlushFinalBlock();
            return Convert.ToBase64String(ms.ToArray());
        }
        #endregion
        #region ========TripleDES加密========
        public string TripleEncryption(string userPassword, string  Key)
        {
            byte[] bytes = Encoding.Unicode.GetBytes(userPassword);
            byte[] keys = ASCIIEncoding.ASCII.GetBytes(Key);
            TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
            tripleDES.Key = keys;  //长度必须为16位或则是24位
            tripleDES.Mode = CipherMode.ECB; //设置运算模式
            ICryptoTransform transform= tripleDES.CreateEncryptor();
            return Convert.ToBase64String(transform.TransformFinalBlock (bytes, 0, bytes.Length));
        }

        #endregion



    static void Main(string[] args)
            {
                string password = "123";
                Byte[] key={12,23,34,45,56,20,35,12};
                Byte[] iv={120,230,110,50,30,11,12,13};
                string  tt = "1234567890123456";
                Encryptions ss = new Encryptions();
                //string dnPword = ss.DESEncryption(password, key, iv);
                string ds = ss.TripleEncryption(password, tt);
            }

  • 相关阅读:
    Flutter——Text组件(文字组件)
    Dart的导包
    Dart 面向对象 类 方法
    Dart中的匿名方法与自执行方法
    Dart的List比较特殊的几个API
    SearchView监听关闭正确方案
    Android选择多图上传
    ListView嵌套ScrollView会出现的问题
    禁用ViewPager的滑动事件
    SQLite相关异常
  • 原文地址:https://www.cnblogs.com/umlzhang/p/1560014.html
Copyright © 2020-2023  润新知