• MD5 加密 解密


    加密:

    View Code
     1 using System;
     2  using System.Collections.Generic;
     3  using System.Linq;
     4  using System.Text;
     5  using System.Security.Cryptography;
     6  using System.IO;
     7  
     8 namespace ENPOT.Manufacture.Security.DL.DataLogic
     9  {
    10      public class CryptUtil
    11      {
    12          static string encryptionKey = "12345678";
    13          static byte[] rgbKey = new byte[0];
    14          static byte[] rgbIV = new byte[] { 10, 20, 30, 40, 50, 60, 70, 80 };
    15  
    16       //编码
    17  
    18         public static string Encrypt(string textToEncrypt)
    19          {
    20              rgbKey = Encoding.UTF8.GetBytes(encryptionKey.Substring(0, 8));
    21              DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
    22              byte[] bytes = Encoding.UTF8.GetBytes(textToEncrypt);
    23              MemoryStream stream = new MemoryStream();
    24              CryptoStream stream2 = new CryptoStream(stream, provider.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
    25              stream2.Write(bytes, 0, bytes.Length);
    26              stream2.FlushFinalBlock();
    27              return Convert.ToBase64String(stream.ToArray());
    28          }

    解码:

    View Code
     1 public static string Decrypt(string textToDecrypt)
     2          {
     3              byte[] buffer = new byte[textToDecrypt.Length];
     4              rgbKey = Encoding.UTF8.GetBytes(encryptionKey.Substring(0, 8));
     5              DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
     6              buffer = Convert.FromBase64String(textToDecrypt);
     7              MemoryStream stream = new MemoryStream();
     8              CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
     9              stream2.Write(buffer, 0, buffer.Length);
    10              stream2.FlushFinalBlock();
    11              return Encoding.UTF8.GetString(stream.ToArray());
    12          }
    13      }
    14  
    15 }
  • 相关阅读:
    Atcoder ARC-104
    [ZJOI2019]线段树
    【XR-2】伤痕
    CF1103B Game with modulo
    [BJOI2019]删数
    AT2402 [ARC072D] Dam
    十六、JMeter实战-跨线程调用token
    十五、JMeter实战-关联-JSON提取器和边界值提取器
    十四、JMeter实战-关联获取token
    十三、JMeter实战-关联-正则表达式
  • 原文地址:https://www.cnblogs.com/zxbzl/p/2961259.html
Copyright © 2020-2023  润新知