Пример #1
0
        /// <summary>
        /// 加密方法
        /// </summary>
        /// <param name="str">加密字符串</param>
        /// <param name="code">加密长度,只有MD5加密有本参数</param>
        /// <param name="type">产生密码类型</param>
        /// <param name="type">密钥</param>
        /// <returns></returns>
        public static string EncryptString(string str, int code, EncryptorType type, string passKey)
        {
            string _tempString = str;

            switch (type)
            {
            case EncryptorType.DES:
                _tempString = new DESEncryptor().EncryptString(str);
                break;

            case EncryptorType.DES3:
                break;

            case EncryptorType.MD5:
                _tempString = MD5Encryptor.MD5(str, code);
                break;

            case EncryptorType.Base64:
                _tempString = new Base64Encryptor().EncryptString(str);
                break;

            case EncryptorType.SHA256:
                _tempString = SHA256Encryptor.SHA256(str);
                break;

            case EncryptorType.DESByEncryptKey:
                _tempString = DESByEncryptKey.EncryptDES(str, passKey);
                break;

            default:
                throw new ArgumentException("无效的加密类型");
            }
            return(_tempString);
        }
Пример #2
0
        /// <summary>
        /// 解密方法
        /// </summary>
        /// <param name="str">需解密字符</param>
        /// <param name="type">解密方法</param>
        /// <returns></returns>
        public static string DecryptString(string str, EncryptorType type, string passKey)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                return(str);
            }

            string _tempString = str;

            switch (type)
            {
            case EncryptorType.DES:
                _tempString = new DESEncryptor().DecryptString(str);
                break;

            case EncryptorType.DES3:
                break;

            case EncryptorType.Base64:
                _tempString = new Base64Encryptor().DecryptString(str);
                break;

            case EncryptorType.DESByEncryptKey:
                _tempString = DESByEncryptKey.DecryptDES(str, passKey);
                break;

            default:
                throw new ArgumentException("无效的加密类型");
            }

            return(_tempString);
        }