• c#解密des


    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace BzdCMS.Common
    {
        public class CryptoJS
        {
            /// <summary>
            /// 解密字符串
            /// </summary>
            /// <param name="str"></param>
            /// <param name="myKey"></param>
            /// <returns></returns>
            public static string DecryptString(string str, string myKey)
            {
                string encryptKeyall = Convert.ToString(myKey);    //定义密钥  
                if (encryptKeyall.Length < 9)
                {
                    for (; ; )
                    {
                        if (encryptKeyall.Length < 9)
                            encryptKeyall += encryptKeyall;
                        else
                            break;
                    }
                }
                string encryptKey = encryptKeyall.Substring(0, 8);
                DESCryptoServiceProvider descsp = new DESCryptoServiceProvider();   //实例化加/解密类对象   
                descsp.Mode = CipherMode.ECB;
    
                byte[] key = Encoding.UTF8.GetBytes(encryptKey); //定义字节数组,用来存储密钥    
                byte[] data = Convert.FromBase64String(str);//定义字节数组,用来存储要解密的字符串  
                byte[] result;
                using (MemoryStream outStream = new MemoryStream())
                {
                    using (CryptoStream encStream = new CryptoStream(outStream, descsp.CreateDecryptor(key, key), CryptoStreamMode.Write))
                    {
                        encStream.Write(data, 0, data.Length);
                        encStream.Close();
                        result = outStream.ToArray();
                    }
                }
                return Encoding.UTF8.GetString(result);
            }
    
        }
    }
  • 相关阅读:
    安卓-登陆页面的实现
    异常
    实用类
    Hashset
    Map
    LinkedList
    arraylist
    继承
    字符串相关代码
    数组代码
  • 原文地址:https://www.cnblogs.com/myLeisureTime/p/14655090.html
Copyright © 2020-2023  润新知