md5 加解密
using JGDJWeb.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Text.RegularExpressions; namespace JGDJWeb.Helper
{
public static class Encrypt
{
#region 加密解密方法
public static string Key = "DKMAB5DE";//加密密钥必须为8位
/// <summary>
/// 加密方法
/// </summary>
/// <param name="pToEncrypt"></param>
/// <returns></returns>
public static string MD5Encrypt(string pToEncrypt)
{
if (string.IsNullOrEmpty(pToEncrypt))
return "";
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
des.Key = ASCIIEncoding.ASCII.GetBytes(Key);
des.IV = ASCIIEncoding.ASCII.GetBytes(Key);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString(); }
/// <summary>
/// 解密算法
/// </summary>
/// <param name="pToDecrypt"></param>
/// <returns></returns>
public static string MD5Decrypt(string pToDecrypt)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
for (int x = 0; x < pToDecrypt.Length / 2; x++)
{
int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
inputByteArray[x] = (byte)i;
}
des.Key = ASCIIEncoding.ASCII.GetBytes(Key);
des.IV = ASCIIEncoding.ASCII.GetBytes(Key);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
StringBuilder ret = new StringBuilder();
return System.Text.Encoding.ASCII.GetString(ms.ToArray());
}
#endregion public static JY_Newss getNews(string newsNo)
{
using (var context = new JGDJEntities())
{
try
{
return context.JY_Newss.Where(c => c.NewsNo == newsNo).First();
}
catch (Exception e)
{
return new JY_Newss();
}
}
} public static string subContent(string content,int length)
{
if (content.Length > length)
{
//content= NoHTML(content);
content = content.Substring(0, length)+"...";
}
return content;
} public static string NoHTML(string Htmlstring)
{
////删除脚本
//Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
////删除style
//Htmlstring = Regex.Replace(Htmlstring, @"<style[^>]*?>.*?</style>", "", RegexOptions.IgnoreCase);
////删除HTML
//Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
//Htmlstring.Replace("<", "");
//Htmlstring.Replace(">", "");
//Htmlstring.Replace("\r\n", ""); /*
* 最好把所有的特殊HTML标记都找出来,然后把与其相对应的Unicode字符一起影射到Hash表内,最后一起都替换掉
*/
//先单独测试,成功后,再把所有模式合并
//注:这两个必须单独处理
//去掉嵌套了HTML标记的JavaScript:(<script)[\\s\\S]*(</script>)
//去掉css标记:(<style)[\\s\\S]*(</style>)
//去掉css标记:\\..*\\{[\\s\\S]*\\}
Htmlstring = Regex.Replace(Htmlstring, "(<script)[\\s\\S]*?(</script>)|(<style)[\\s\\S]*?(</style>)", " ", RegexOptions.IgnoreCase);
//htmlStream = RemoveTag(htmlStream, "script");
//htmlStream = RemoveTag(htmlStream, "style");
//去掉普通HTML标记:<[^>]+>
//替换空格: |&|­| |
Htmlstring = Regex.Replace(Htmlstring, "<[^>]+>| |&|­| ||•|<|>", " ", RegexOptions.IgnoreCase);
//htmlStream = RemoveTag(htmlStream);
//替换左尖括号
//htmlStream = Regex.Replace(htmlStream, "<", "<");
//替换右尖括号
//htmlStream = Regex.Replace(htmlStream, ">", ">");
//替换空行
//htmlStream = Regex.Replace(htmlStream, "[\n|\r|\t]", " ");//[\n|\r][\t*| *]*[\n|\r]
Htmlstring = Regex.Replace(Htmlstring, "(\r\n[\r|\n|\t| ]*\r\n)|(\n[\r|\n|\t| ]*\n)", "\r\n");
Htmlstring = Regex.Replace(Htmlstring, "[\t| ]{1,}", " ");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
return Htmlstring;
} public static string GetXML(string type)
{
string classNo = "";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ApplicationBase +"/XML/Menu.xml");
XmlNodeList xnl = xmlDoc["root"].ChildNodes;
foreach (XmlNode lastNode in xnl)
{
if (type == lastNode.Attributes["id"].Value.ToString())
{
foreach (XmlNode node in lastNode.ChildNodes)
{
classNo = node.InnerText;
}
classNo = MD5Encrypt(classNo);
}
}
return classNo;
} public static string GetClientIP()
{
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
} if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
} public static void UpdateClick(string newsNo)
{
using (var context = new JGDJEntities())
{
var news = context.JY_Newss.Where(j => j.NewsNo == newsNo).FirstOrDefault();
if (news != null)
{
if (news.Click == null)
{
news.Click = 1;
}
else
{
news.Click += 1;
}
var clickD = new JY_NewsClick_D();
clickD.CDate = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
clickD.NewsID = news.NewsID;
clickD.CreateTime = DateTime.Now;
clickD.IP = GetClientIP();
context.JY_NewsClick_D.AddObject(clickD);
var clickY = context.JY_NewsClick_Y.Where(j => j.NewsID == news.NewsID&&j.Years==DateTime.Now.Year).FirstOrDefault();
if (clickY != null)
{
switch (DateTime.Now.Month)
{
case 1: clickY.M1 = clickY.M1 == null ? 1 : (clickY.M1 + 1); break;
case 2: clickY.M2 = clickY.M2 == null ? 1 : (clickY.M2 + 1); break;
case 3: clickY.M3 = clickY.M3 == null ? 1 : (clickY.M3 + 1); break;
case 4: clickY.M4 = clickY.M4 == null ? 1 : (clickY.M4 + 1); break;
case 5: clickY.M5 = clickY.M5 == null ? 1 : (clickY.M5 + 1); break;
case 6: clickY.M6 = clickY.M6 == null ? 1 : (clickY.M6 + 1); break;
case 7: clickY.M7 = clickY.M7 == null ? 1 : (clickY.M7 + 1); break;
case 8: clickY.M8 = clickY.M8 == null ? 1 : (clickY.M8 + 1); break;
case 9: clickY.M9 = clickY.M9 == null ? 1 : (clickY.M9 + 1); break;
case 10: clickY.M10 = clickY.M10 == null ? 1 : (clickY.M10 + 1); break;
case 11: clickY.M11 = clickY.M11 == null ? 1 : (clickY.M11 + 1); break;
case 12: clickY.M12 = clickY.M12 == null ? 1 : (clickY.M12 + 1); break;
}
}
else
{
clickY = new JY_NewsClick_Y();
clickY.NewsID = news.NewsID;
clickY.Years = DateTime.Now.Year;
switch (DateTime.Now.Month)
{
case 1: clickY.M1 = clickY.M1 == null ? 1 : (clickY.M1 + 1); break;
case 2: clickY.M2 = clickY.M2 == null ? 1 : (clickY.M2 + 1); break;
case 3: clickY.M3 = clickY.M3 == null ? 1 : (clickY.M3 + 1); break;
case 4: clickY.M4 = clickY.M4 == null ? 1 : (clickY.M4 + 1); break;
case 5: clickY.M5 = clickY.M5 == null ? 1 : (clickY.M5 + 1); break;
case 6: clickY.M6 = clickY.M6 == null ? 1 : (clickY.M6 + 1); break;
case 7: clickY.M7 = clickY.M7 == null ? 1 : (clickY.M7 + 1); break;
case 8: clickY.M8 = clickY.M8 == null ? 1 : (clickY.M8 + 1); break;
case 9: clickY.M9 = clickY.M9 == null ? 1 : (clickY.M9 + 1); break;
case 10: clickY.M10 = clickY.M10 == null ? 1 : (clickY.M10 + 1); break;
case 11: clickY.M11 = clickY.M11 == null ? 1 : (clickY.M11 + 1); break;
case 12: clickY.M12 = clickY.M12 == null ? 1 : (clickY.M12 + 1); break;
}
context.JY_NewsClick_Y.AddObject(clickY);
}
var classList = context.JY_NewsClass.Where(c => c.NewsNo == news.NewsNo).Select(c => c.ClassNo).ToList();
foreach (var item in classList)
{
var classs = context.JY_News_Classs.Where(j => j.ClassNo == item).FirstOrDefault();
if (classs != null)
{
if (classs.Click == null)
{
classs.Click = 1;
}
else
{
classs.Click += 1;
}
var CclickD = new JY_ClasssClick_D();
CclickD.CDate = int.Parse(DateTime.Now.ToString("yyyyMMdd"));
CclickD.ClassID = classs.ClassID;
context.JY_ClasssClick_D.AddObject(CclickD);
}
var CclickY = context.JY_ClasssClick_Y.Where(j => j.ClassID == classs.ClassID && j.Years == DateTime.Now.Year).FirstOrDefault();
if (CclickY != null)
{
switch (DateTime.Now.Month)
{
case 1: CclickY.M1 = CclickY.M1 == null ? 1 : (CclickY.M1 + 1); break;
case 2: CclickY.M2 = CclickY.M2 == null ? 1 : (CclickY.M2 + 1); break;
case 3: CclickY.M3 = CclickY.M3 == null ? 1 : (CclickY.M3 + 1); break;
case 4: CclickY.M4 = CclickY.M4 == null ? 1 : (CclickY.M4 + 1); break;
case 5: CclickY.M5 = CclickY.M5 == null ? 1 : (CclickY.M5 + 1); break;
case 6: CclickY.M6 = CclickY.M6 == null ? 1 : (CclickY.M6 + 1); break;
case 7: CclickY.M7 = CclickY.M7 == null ? 1 : (CclickY.M7 + 1); break;
case 8: CclickY.M8 = CclickY.M8 == null ? 1 : (CclickY.M8 + 1); break;
case 9: CclickY.M9 = CclickY.M9 == null ? 1 : (CclickY.M9 + 1); break;
case 10: CclickY.M10 = CclickY.M10 == null ? 1 : (CclickY.M10 + 1); break;
case 11: CclickY.M11 = CclickY.M11 == null ? 1 : (CclickY.M11 + 1); break;
case 12: CclickY.M12 = CclickY.M12 == null ? 1 : (CclickY.M12 + 1); break;
}
}
else
{
CclickY = new JY_ClasssClick_Y();
CclickY.ClassID = classs.ClassID;
CclickY.Years = DateTime.Now.Year;
switch (DateTime.Now.Month)
{
case 1: CclickY.M1 = CclickY.M1 == null ? 1 : (CclickY.M1 + 1); break;
case 2: CclickY.M2 = CclickY.M2 == null ? 1 : (CclickY.M2 + 1); break;
case 3: CclickY.M3 = CclickY.M3 == null ? 1 : (CclickY.M3 + 1); break;
case 4: CclickY.M4 = CclickY.M4 == null ? 1 : (CclickY.M4 + 1); break;
case 5: CclickY.M5 = CclickY.M5 == null ? 1 : (CclickY.M5 + 1); break;
case 6: CclickY.M6 = CclickY.M6 == null ? 1 : (CclickY.M6 + 1); break;
case 7: CclickY.M7 = CclickY.M7 == null ? 1 : (CclickY.M7 + 1); break;
case 8: CclickY.M8 = CclickY.M8 == null ? 1 : (CclickY.M8 + 1); break;
case 9: CclickY.M9 = CclickY.M9 == null ? 1 : (CclickY.M9 + 1); break;
case 10: CclickY.M10 = CclickY.M10 == null ? 1 : (CclickY.M10 + 1); break;
case 11: CclickY.M11 = CclickY.M11 == null ? 1 : (CclickY.M11 + 1); break;
case 12: CclickY.M12 = CclickY.M12 == null ? 1 : (CclickY.M12 + 1); break;
}
context.JY_ClasssClick_Y.AddObject(CclickY);
}
}
context.SaveChanges();
}
}
} }
}
md5 加解密的更多相关文章
- vue 核心加解密工具类 方法
1 /* base64 加解密 2 */ 3 export let Base64 = require('js-base64').Base64 4 5 /* md5 加解密 6 */ 7 export ...
- 前后端java+vue 实现rsa 加解密与摘要签名算法
RSA 加密.解密.签名.验签.摘要,前后端java+vue联调测试通过 直接上代码 // 注意:加密密文与签名都是唯一的,不会变化.// 注意:vue 端密钥都要带pem格式.java 不要带pem ...
- DES,AeS加解密,MD5,SHA加密
1.DES一共就有4个参数参与运作:明文.密文.密钥.向量.其中这4者的关系可以理解为: 密文=明文+密钥+向量: 明文=密文-密钥-向量: 为什么要向量这个参数呢?因为如果有一篇文章,有几个词重复, ...
- Node.js的DES加解密和MD5加密
最基本的就是经常用的md5加密算法 代码如下 var MD5=function (data) { var _encrymd5 = require('crypto').createHas ...
- 2.Java 加解密技术系列之 MD5
Java 加解密技术系列之 MD5 序 背景 正文 结束语 序 上一篇文章中,介绍了最基础的编码方式 — — BASE64,也简单的提了一下编码的原理.这篇文章继续加解密的系列,当然也是介绍比较基础的 ...
- Asp.Net Core 2.0 项目实战(7)MD5加密、AES&DES对称加解密
本文目录 1. 摘要 2. MD5加密封装 3. AES的加密.解密 4. DES加密/解密 5. 总结 1. 摘要 C#中常用的一些加密和解密方案,如:md5加密.RSA加密与解密和DES加密等, ...
- Python用户名密码登录系统(MD5加密并存入文件,三次输入错误将被锁定)及对字符串进行凯撒密码加解密操作
# -*- coding: gb2312 -*- #用户名密码登录系统(MD5加密并存入文件)及对字符串进行凯撒密码加解密操作 #作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.co ...
- MD5+DES在C#.NET与Java/Android中的加解密使用
一.背景后台(C#.NET)使用一个MD5+DES的加解密算法,查了下,很多网友都使用了这个算法.在Android里,也需要这个算法,如何把这个加解密算法切换成Java版,成了难题.毕竟好久没涉及到这 ...
- md5加密,md5加盐加密和解密
package com.java.test; import java.security.MessageDigest; import java.security.SecureRandom; import ...
随机推荐
- C++机试笔记
- POJ:3262-Protecting the Flowers
Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8606 Accepted: 347 ...
- 大话卷积神经网络(CNN)
这几年深度学习快速发展,在图像识别.语音识别.物体识别等各种场景上取得了巨大的成功,例如AlphaGo击败世界围棋冠军,iPhone X内置了人脸识别解锁功能等等,很多AI产品在世界上引起了很大的 ...
- Kali Linux 搜狗输入法安装
1.下载 搜狗输入法 for Linux http://pinyin.sogou.com/linux/ //有64位和32位的deb包 我这里下载的是 : sogoupinyin_2.1.0.0086 ...
- Java中数据类型转换&基本类型变量和对象型变量
1.Java的数据类型分为三大类 布尔型,字符型和数值型 其中数值型又分为整型和浮点型 2.Java的变量类型 布尔型 boolean 字符型 char 整型 byte,short,int,lo ...
- 网易OpenStack部署运维实战
OpenStack自2010年项目成立以来,已经有超过200个公司加入了 OpenStack 项目,目前参与 OpenStack 项目的开发人员有 17,000+,而且这些数字还在增加,作为一个开源的 ...
- 网易云深度剖析Kubernetes优化与实践
欢迎访问网易云社区,了解更多网易技术产品运营经验. 10 月 15 日,聚焦 Kubernetes 中国行业应用与技术落地的首届中国 Kubernetes 用户大会(KEUC)在杭州成功举办.本次大会 ...
- 《Cracking the Coding Interview》——第5章:位操作——题目7
2014-03-19 06:27 题目:有一个数组里包含了0~n中除了某个整数m之外的所有整数,你要设法找出这个m.限制条件为每次你只能用O(1)的时间访问第i个元素的第j位二进制位. 解法:0~n的 ...
- Windows Phone 图片扩展类
using System.IO; using System.Text; using System.Net; using System.Threading.Tasks; using System.Win ...
- 孤荷凌寒自学python第五十九天尝试使用python来读访问远端MongoDb数据服务
孤荷凌寒自学python第五十九天尝试使用python来读访问远端MongoDb数据服务 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第五天.今天的感觉是,mongoDB数 ...