zoukankan      html  css  js  c++  java
  • C# DES加解密

        public static string EncodeDES(string text, string Key)
            {
                byte[] keyBytes = Encoding.ASCII.GetBytes(Key.Substring(0, 8));
                byte[] keyIV = keyBytes;
                byte[] inputByteArray = Encoding.UTF8.GetBytes(text);
                DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
    
                provider.Mode = CipherMode.ECB;//兼容其他语言的Des加密算法  
                provider.Padding = PaddingMode.PKCS7;//自动补0
    
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, provider.CreateEncryptor(keyBytes, keyIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
    
                return Convert.ToBase64String(mStream.ToArray());
             
            }
    
    
            public static string DecodeDES(string text, string key)
            {
                byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
                byte[] keyIV = keyBytes;
                byte[] inputByteArray = Convert.FromBase64String(text);
                DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
                provider.Padding = PaddingMode.PKCS7;
                provider.Mode = CipherMode.ECB;//兼容其他语言的Des加密算法  
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, provider.CreateDecryptor(keyBytes, keyIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Encoding.UTF8.GetString(mStream.ToArray());
            }
    View Code
  • 相关阅读:
    判断ImageIcon创建成功
    Node中的explorer views的双击事件
    Oracle数据类型
    Sql三种行转列
    数据库迁移
    并发采集同一站点被封的解决方案
    .net获取版本号的三种方法
    List转DataSet
    Orcale自增长主键
    python学习笔记数字和表达式
  • 原文地址:https://www.cnblogs.com/CnnBlog/p/14435750.html
Copyright © 2011-2022 走看看