MD5/Base64/DES是常用来对用户身份验证的算法,本人陆续公开了自己常用的这三种算法的源代码,不足之处,希望大家批评指正。
 
用C#实现DES加密解密_休闲using System;
用C#实现DES加密解密_休闲using System.Security.Cryptography;
用C#实现DES加密解密_休闲using System.Text;
用C#实现DES加密解密_休闲using System.IO;
用C#实现DES加密解密_休闲
用C#实现DES加密解密_休闲namespace Common
用C#实现DES加密解密_休闲...{
用C#实现DES加密解密_休闲        /**//// <summary>
用C#实现DES加密解密_休闲        /// DESEncrypt加密解密算法。
用C#实现DES加密解密_休闲        /// </summary>
用C#实现DES加密解密_休闲        public sealed class DESEncrypt
用C#实现DES加密解密_休闲        ...{
用C#实现DES加密解密_休闲                private DESEncrypt()
用C#实现DES加密解密_休闲                ...{
用C#实现DES加密解密_休闲                        //
用C#实现DES加密解密_休闲                        // TODO: 在此处添加构造函数逻辑
用C#实现DES加密解密_休闲                        //
用C#实现DES加密解密_休闲                }
用C#实现DES加密解密_休闲
用C#实现DES加密解密_休闲                private static string key = "zhoufoxcn";
用C#实现DES加密解密_休闲
用C#实现DES加密解密_休闲                /**//// <summary>
用C#实现DES加密解密_休闲                /// 对称加密解密的密钥
用C#实现DES加密解密_休闲                /// </summary>
用C#实现DES加密解密_休闲                public static string Key
用C#实现DES加密解密_休闲                ...{
用C#实现DES加密解密_休闲                        get
用C#实现DES加密解密_休闲                        ...{
用C#实现DES加密解密_休闲                                return key;
用C#实现DES加密解密_休闲                        }
用C#实现DES加密解密_休闲                        set
用C#实现DES加密解密_休闲                        ...{
用C#实现DES加密解密_休闲                                key = value;
用C#实现DES加密解密_休闲                        }
用C#实现DES加密解密_休闲                }
用C#实现DES加密解密_休闲
用C#实现DES加密解密_休闲                /**//// <summary>
用C#实现DES加密解密_休闲                /// DES加密
用C#实现DES加密解密_休闲                /// </summary>
用C#实现DES加密解密_休闲                /// <param name="encryptString"></param>
用C#实现DES加密解密_休闲                /// <returns></returns>
用C#实现DES加密解密_休闲                public static string DesEncrypt(string encryptString)
用C#实现DES加密解密_休闲                ...{
用C#实现DES加密解密_休闲                        byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
用C#实现DES加密解密_休闲                        byte[] keyIV = keyBytes;
用C#实现DES加密解密_休闲                        byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
用C#实现DES加密解密_休闲                        DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
用C#实现DES加密解密_休闲                        MemoryStream mStream = new MemoryStream();
用C#实现DES加密解密_休闲                        CryptoStream cStream = new CryptoStream(mStream, provider.CreateEncryptor(keyBytes, keyIV), CryptoStreamMode.Write);
用C#实现DES加密解密_休闲                        cStream.Write(inputByteArray, 0, inputByteArray.Length);
用C#实现DES加密解密_休闲                        cStream.FlushFinalBlock();
用C#实现DES加密解密_休闲                        return Convert.ToBase64String(mStream.ToArray());
用C#实现DES加密解密_休闲                }
用C#实现DES加密解密_休闲
用C#实现DES加密解密_休闲                /**//// <summary>
用C#实现DES加密解密_休闲                /// DES解密
用C#实现DES加密解密_休闲                /// </summary>
用C#实现DES加密解密_休闲                /// <param name="decryptString"></param>
用C#实现DES加密解密_休闲                /// <returns></returns>
用C#实现DES加密解密_休闲                public static string DesDecrypt(string decryptString)
用C#实现DES加密解密_休闲                ...{
用C#实现DES加密解密_休闲                        byte[] keyBytes = Encoding.UTF8.GetBytes(key.Substring(0, 8));
用C#实现DES加密解密_休闲                        byte[] keyIV = keyBytes;
用C#实现DES加密解密_休闲                        byte[] inputByteArray = Convert.FromBase64String(decryptString);
用C#实现DES加密解密_休闲                        DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
用C#实现DES加密解密_休闲                        MemoryStream mStream = new MemoryStream();
用C#实现DES加密解密_休闲                        CryptoStream cStream = new CryptoStream(mStream, provider.CreateDecryptor(keyBytes, keyIV), CryptoStreamMode.Write);
用C#实现DES加密解密_休闲                        cStream.Write(inputByteArray, 0, inputByteArray.Length);
用C#实现DES加密解密_休闲                        cStream.FlushFinalBlock();
用C#实现DES加密解密_休闲                        return Encoding.UTF8.GetString(mStream.ToArray());
用C#实现DES加密解密_休闲                }
用C#实现DES加密解密_休闲        }
用C#实现DES加密解密_休闲}