• C#加密与解密


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Security.Cryptography;
    using System.IO;

    namespace Secrituy
    {
       
       


        public class Secure
        {
            private static byte[] DESKey = new byte[]{11,23,93,102,72,41,18,12};
            private static byte[] DESIV = new byte[] { 75, 158, 46, 97, 78, 57, 17, 36 };

            public static string Encode(string Encode_String)
            {
                DESCryptoServiceProvider objDES = new DESCryptoServiceProvider();
                MemoryStream objMemoryStream = new MemoryStream();
                CryptoStream objCryptoStream = new CryptoStream(objMemoryStream, objDES.CreateEncryptor(DESKey, DESIV), CryptoStreamMode.Write);
                StreamWriter objStreamWriter = new StreamWriter(objCryptoStream);
                objStreamWriter.Write(Encode_String);
                objStreamWriter.Flush();
                objCryptoStream.FlushFinalBlock();
                objMemoryStream.Flush();
                return Convert.ToBase64String(objMemoryStream.GetBuffer(), 0, (int)objMemoryStream.Length);
            }

            public static string Decode(string Encode_String)
            {
                DESCryptoServiceProvider objDES = new DESCryptoServiceProvider();
                byte[] input = Convert.FromBase64String(Encode_String);
                MemoryStream objMemoryStream = new MemoryStream(input);
                CryptoStream objCryptoStream = new CryptoStream(objMemoryStream, objDES.CreateDecryptor(DESKey, DESIV), CryptoStreamMode.Read);
                StreamReader objStreamReader = new StreamReader(objCryptoStream);
                return objStreamReader.ReadToEnd();
            }
        }
    }

  • 相关阅读:
    JS判断是否是IE浏览器
    JS在页面光标位置插入新内容
    JS限制文本框输入金额,保留2位小数
    JS格式化日期方法
    MySQL数据库中16进制进行位运算
    Java过滤特殊字符的正则表达式
    JAVA查看线程信息
    win7 安装Redis
    JAVA获取catch中的异常信息
    cpu占用率过高debug
  • 原文地址:https://www.cnblogs.com/DaiWei/p/365912.html
Copyright © 2020-2023  润新知