• C# des 加密 解密


    代码
        public class EncryptDecrypt
        {
            
    public static string EncryptString(string mes, string key)
            {
                
    byte[] inputBytes = ASCIIEncoding.UTF8.GetBytes(mes);

                MemoryStream outputStream 
    = new MemoryStream();
                DESCryptoServiceProvider des 
    = new DESCryptoServiceProvider();
                des.Key 
    = ASCIIEncoding.ASCII.GetBytes(key);
                des.IV 
    = ASCIIEncoding.ASCII.GetBytes(key);
                ICryptoTransform desencrypt 
    = des.CreateEncryptor();
                CryptoStream cryptostream 
    = new CryptoStream(outputStream, desencrypt, CryptoStreamMode.Write);
                cryptostream.Write(inputBytes, 
    0, inputBytes.Length);
                cryptostream.FlushFinalBlock();
                cryptostream.Close();

                
    string outputString = Convert.ToBase64String(outputStream.ToArray());
                
    return outputString;
            }

            
    public static string DecryptString(string mes, string key)
            {
                
    byte[] inputBytes = Convert.FromBase64String(mes);

                MemoryStream outputStream 
    = new MemoryStream();
                DESCryptoServiceProvider des 
    = new DESCryptoServiceProvider();
                des.Key 
    = ASCIIEncoding.ASCII.GetBytes(key);
                des.IV 
    = ASCIIEncoding.ASCII.GetBytes(key);
                ICryptoTransform desencrypt 
    = des.CreateDecryptor();
                CryptoStream cryptostream 
    = new CryptoStream(outputStream, desencrypt, CryptoStreamMode.Write);
                cryptostream.Write(inputBytes, 
    0, inputBytes.Length);
                cryptostream.FlushFinalBlock();
                cryptostream.Close();

                
    string outputString = ASCIIEncoding.UTF8.GetString(outputStream.ToArray());
                
    return outputString;
            }
        }
  • 相关阅读:
    使用Python的Mock库进行PySpark单元测试
    库龄报表的相关知识
    使用PlanViz进行ABAP CDS性能分析
    Spark SQL中列转行(UNPIVOT)的两种方法
    Spark中的一些概念
    使用Visual Studio Code进行ABAP开发
    2019年的几个目标
    Dom--样式操作
    Dom选择器--内容文本操作
    Javascript面向
  • 原文地址:https://www.cnblogs.com/bloodofhero/p/1737167.html
Copyright © 2020-2023  润新知