zoukankan      html  css  js  c++  java
  • 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);
            }
    
        }
    }
  • 相关阅读:
    android videoView 加载等待
    LocalBroadcastManager
    sessionStorage 、localStorage
    javascript 数组、json连接
    properties 文件注意事项
    nutz 使用beetl
    [Git/Github] ubuntu 14.0 下github 配置
    【UNIX环境编程、操作系统】孤儿进程和僵尸进程
    【操作系统】进程间通信
    【操作系统】线程
  • 原文地址:https://www.cnblogs.com/myLeisureTime/p/14655090.html
Copyright © 2011-2022 走看看