zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    如何在。net中扩展本机消息框对话框
    一个显示角色映射的对话框
    键盘消息/加速器处理MFC对话框的应用程序
    立即显示WinForms使用如图所示()事件
    XFontDialog——定制CFontDialog第一部分:添加字体过滤器
    一个动画风格的对话框类
    类似vista的任务对话框
    简单而强大的可调整大小的对话框
    /etc/hosts
    /etc/sysconfig/network-scripts/ifcfg-ensxx
  • 原文地址:https://www.cnblogs.com/zxbzl/p/2961259.html
Copyright © 2011-2022 走看看