zoukankan      html  css  js  c++  java
  • 加密解密

          /// <summary>
            /// 加密 Des密钥
            /// </summary>
            /// <param name="original"></param>
            /// <returns></returns>
            public  byte[] MakeMD5(byte[] original)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                byte[] keyhash = hashmd5.ComputeHash(original);
                hashmd5 = null;
                return keyhash;
            }
    
           
            /// <summary>
            /// 加密 穿入密钥 默认zkl
            /// </summary>
            /// <param name="original"></param>
            /// <param name="key"></param>
            /// <returns></returns>
            public  string Encrypt(string original, string key)
            {
                byte[] buff = System.Text.Encoding.Default.GetBytes(original);
                byte[] kb = System.Text.Encoding.Default.GetBytes(key);
    
                TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
                des.Key = MakeMD5(kb);
                des.Mode = CipherMode.ECB;
                byte[] res = des.CreateEncryptor().TransformFinalBlock(buff, 0, buff.Length);
    
                return Convert.ToBase64String(res);
            }
    
    
            /// <summary>
            /// 解密 默认密钥
            /// </summary>
            /// <param name="original"></param>
            /// <returns></returns>
            public  string Decrypt(string original)
            {
    
                byte[] source = Convert.FromBase64String(original);//原文
                byte[] key = System.Text.Encoding.Default.GetBytes("zkl");//密钥
    
                TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
                des.Key = MakeMD5(key);
                des.Mode = CipherMode.ECB;
    
               byte[] pass=   des.CreateDecryptor().TransformFinalBlock(source, 0, source.Length);
    
    
               return  Encoding.Default.GetString(pass);
    
            }
  • 相关阅读:
    Java_适配器模式
    linux常用命令整理
    (转)使用隐藏的iframe 隐藏form提交,仿AJax无刷新提交,可以实现无刷新上传文件
    mysql添加并返回主键
    学习RMI
    关于bcprov-jdk16
    JavaScript在页面中的引用方法
    通过CFX发布WebService(一)
    字符串和json数据的转换
    MD5 加密与解密
  • 原文地址:https://www.cnblogs.com/kunlunmountain/p/5464771.html
Copyright © 2011-2022 走看看