zoukankan      html  css  js  c++  java
  • DES加密

     string key = "hdyxsjtd";//密匙8个字符
            //加密
            public string JiaMi(string sourceString)
            {
                byte[] keyBytes = Encoding.UTF8.GetBytes(key);
                byte[] keyIV = keyBytes;
                byte[] inputByteArray = Encoding.UTF8.GetBytes(sourceString);
                DESCryptoServiceProvider desProvider = new DESCryptoServiceProvider();
                MemoryStream memStream = new MemoryStream();
                CryptoStream crypStream = new CryptoStream(memStream, desProvider.CreateEncryptor(keyBytes, keyIV), CryptoStreamMode.Write);
                crypStream.Write(inputByteArray, 0, inputByteArray.Length);
                crypStream.FlushFinalBlock();
                return Convert.ToBase64String(memStream.ToArray());
            }

            //解密的函数
            public string JieMi(string encryptString)
            {
                byte[] keyBytes = Encoding.UTF8.GetBytes(key);
                byte[] keyIV = keyBytes;
                byte[] inputByteArray = Convert.FromBase64String(encryptString);
                DESCryptoServiceProvider desProvider = new DESCryptoServiceProvider();
                MemoryStream memStream = new MemoryStream();
                CryptoStream crypStream = new CryptoStream(memStream, desProvider.CreateDecryptor(keyBytes, keyIV), CryptoStreamMode.Write);
                crypStream.Write(inputByteArray, 0, inputByteArray.Length);
                crypStream.FlushFinalBlock();
                return Encoding.UTF8.GetString(memStream.ToArray());
            }

  • 相关阅读:
    前端诡异参数start
    JDK常用命令(二)jstack
    JDK常用命令(一)jps、jstat
    C#反射之基础应用
    c#实现随鼠标移动窗体
    c# 使用api函数 ShowWindowAsync 控制窗体
    简单例子快速了解事件处理和委托 event delegate
    通过 WIN32 API 实现嵌入程序窗体
    C# 轻松实现对窗体(Form)换肤[转]
    C#正则表达式匹配HTML中的图片路径
  • 原文地址:https://www.cnblogs.com/Iyce/p/2738656.html
Copyright © 2011-2022 走看看