首先,感谢我的技术总监,夏总,在这里将滚码加密类做出整理 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Security.Cryptography; using System.IO; using System.Text; namespace WebTEST { public class EncriptManager { // Fields private KeyManager _keyManager; private SymCryptography _maskCriptor; // Methods public EncriptManager() { this._keyManager = new KeyManager(); this._maskCriptor = new SymCryptography("TripleDES"); this._maskCriptor.Key = "Web%HMKMJgfccg$%%^^&kkksl12312%&"; } public EncriptManager(string key) { this._keyManager = new KeyManager(); this._maskCriptor = new SymCryptography("TripleDES"); this._maskCriptor.Key = key; } public static void clearBytes(byte[] Buffer) { if (Buffer == null) { throw new ArgumentException("Buffer"); } for (int num1 = 0; num1 <= (Buffer.Length - 1); num1++) { Buffer[num1] = 0; } } public static byte[] createRandomSalt(int Length) { byte[] buffer1; if (Length >= 1) { buffer1 = new byte[Length]; } else { buffer1 = new byte[1]; } RNGCryptoServiceProvider provider1 = new RNGCryptoServiceProvider(); provider1.GetBytes(buffer1); return buffer1; } public string Decript(string str) { SymCryptography cryptography1 = new SymCryptography("TripleDES"); string text1 = this._maskCriptor.Decrypt(str); if (text1.Length > 3) { int num1; string text2 = text1.Substring(0, 3); string text3 = text1.Substring(3, text1.Length - 3); string text4 = text3; if (int.TryParse(text2, out num1)) { string text5 = this._keyManager.GetKey(num1); cryptography1.Key = text5; return cryptography1.Decrypt(text3); } } return text1; } public string DecriptStatic(string str) { SymCryptography cryptography1 = new SymCryptography("TripleDES"); cryptography1.Key = "Web%HMKMJgfccg$%%^^&kkksl12312%&"; return cryptography1.Decrypt(str); } public string DecriptStatic(string str, string seed) { SymCryptography cryptography1 = new SymCryptography("TripleDES"); cryptography1.Key = seed; cryptography1.Salt = seed; return cryptography1.Decrypt(str); } public string Encript(string str) { string text3; SymCryptography cryptography1 = new SymCryptography("TripleDES"); Random random1 = new Random(); int num1 = random1.Next(0, 0x80); string text1 = this._keyManager.GetKey(num1); cryptography1.Key = text1; string text2 = cryptography1.Encrypt(str); if (num1 < 10) { text3 = "00" + num1.ToString(); } else if (num1 < 100) { text3 = "0" + num1.ToString(); } else { text3 = num1.ToString(); } string text4 = text3.Substring(0, 3) + text2; return this._maskCriptor.Encrypt(text4); } public string EncriptStatic(string str) { SymCryptography cryptography1 = new SymCryptography("TripleDES"); cryptography1.Key = "Web%HMKMJgfccg$%%^^&kkksl12312%&"; return cryptography1.Encrypt(str); } public string EncriptStatic(string str, out string seed) { Random random1 = new Random(); int num1 = random1.Next(0x186a0, 0xf423f); string text1 = num1.ToString(); SymCryptography cryptography1 = new SymCryptography("TripleDES"); cryptography1.Key = text1; seed = text1; return cryptography1.Encrypt(str); } public string EncriptStatic(string str, string seed) { SymCryptography cryptography1 = new SymCryptography("TripleDES"); cryptography1.Key = seed; cryptography1.Salt = seed; return cryptography1.Encrypt(str); } } internal class Hash { // Methods public Hash() { this.mCryptoService = new SHA1Managed(); } public Hash(Hash.ServiceProviderEnum serviceProvider) { switch (serviceProvider) { case Hash.ServiceProviderEnum.SHA1: { this.mCryptoService = new SHA1Managed(); return; } case Hash.ServiceProviderEnum.SHA256: { this.mCryptoService = new SHA256Managed(); return; } case Hash.ServiceProviderEnum.SHA384: { this.mCryptoService = new SHA384Managed(); return; } case Hash.ServiceProviderEnum.SHA512: { this.mCryptoService = new SHA512Managed(); return; } case Hash.ServiceProviderEnum.MD5: { this.mCryptoService = new MD5CryptoServiceProvider(); return; } } } public Hash(string serviceProviderName) { try { this.mCryptoService = (HashAlgorithm)CryptoConfig.CreateFromName(serviceProviderName.ToUpper());