tnblog
首页
视频
资源
登录

对字符串进行解压(加密以及解密)

5140人阅读 2020/3/31 15:17 总访问:413408 评论:0 收藏:0 手机
分类: ASP.NET

去除JSON需要过滤标记
public static string ToJsonFilter(this string input)
        {
            string htmlstring = input;
            //删除脚本
            htmlstring = Regex.Replace(htmlstring, @"<script[^>]*?>.*?</script>", "",
              RegexOptions.IgnoreCase);
            htmlstring = htmlstring.Replace("\r\n", "");
            htmlstring = htmlstring.Replace("\n", "");
            htmlstring = Regex.Replace(htmlstring, "\"", "", RegexOptions.IgnoreCase);
            htmlstring = Regex.Replace(htmlstring, "'", "", RegexOptions.IgnoreCase);
            htmlstring = Regex.Replace(htmlstring, "\r", "", RegexOptions.IgnoreCase);
            return htmlstring;
        }
加密字符串(参数编码:UTF8)(加密过的字符串:decryptString,密钥:pKey,初始化向量:iKey)
public static string NDChannel_EncryptDES(string decryptString, string pKey, string iKey)
        {
            if (string.IsNullOrEmpty(decryptString)) return string.Empty;
            try
            {
                byte[] privateKey = Encoding.UTF8.GetBytes(pKey.PadRight(8).Substring(0, 8));
                byte[] publicKey = Encoding.UTF8.GetBytes(iKey.PadRight(8).Substring(0, 8));
                byte[] inputByteArray = Encoding.UTF8.GetBytes(decryptString);
                DESCryptoServiceProvider dcsp = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, dcsp.CreateEncryptor(privateKey, publicKey), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Convert.ToBase64String(mStream.ToArray());
            }
            catch
            {
                return string.Empty;
            }
        }
解密字符串(参数编码:UTF8)
public static string NDChannel_DecryptDES(string decryptString, string pKey, string iKey)
        {
            if (string.IsNullOrEmpty(decryptString)) return string.Empty;
            try
            {
                byte[] privateKey = Encoding.UTF8.GetBytes(pKey.PadRight(8).Substring(0, 8));
                byte[] publicKey = Encoding.UTF8.GetBytes(iKey.PadRight(8).Substring(0, 8));
                byte[] inputByteArray = Convert.FromBase64String(decryptString);
                DESCryptoServiceProvider dcsp = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, dcsp.CreateDecryptor(privateKey, publicKey), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Encoding.UTF8.GetString(mStream.ToArray());
            }
            catch
            {
                return string.Empty;
            }
        }


评价
当你知道迷惑时,并不可怜,当你不知道迷惑时,才是最可怜的。
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术