去除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;
}
}