• 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);
            }
    
        }
    }
  • 相关阅读:
    字符串去特定字符
    字符串的查找删除
    输出梯形
    元素节点的 innerText、innerHTML、outerHTML、outerText
    JavaScript DOM 特殊集合Collection
    Collection 访问方式
    JS Browser BOM
    异常
    JCBD
    try-with-resources 方式关闭注意事项
  • 原文地址:https://www.cnblogs.com/myLeisureTime/p/14655090.html
Copyright © 2020-2023  润新知