当前位置: 首页 > news >正文

黄骅吧招聘信息/seo的作用

黄骅吧招聘信息,seo的作用,微网站报价,西安做网站费用/// ///类名称 :CryptTools///类说明 :加解密算法///作者 :小老虎2///完成日期 :/// public static classCryptTools{/// ///方法说明 :加密方法///作者  :///完成日期 :/// /// 需要加密的明…

///

///类名称 :CryptTools///类说明 :加解密算法///作者 :小老虎2///完成日期 :///

public static classCryptTools

{///

///方法说明 :加密方法///作者  :///完成日期 :///

/// 需要加密的明文内容

/// 加密密钥

/// 返回加密后密文字符串

public static string Encrypt(string content, stringsecret)

{if ((content == null) || (secret == null) || (content.Length == 0) || (secret.Length == 0))throw new ArgumentNullException("Invalid Argument");byte[] Key =GetKey(secret);byte[] ContentByte =Encoding.Unicode.GetBytes(content);

MemoryStream MSTicket= newMemoryStream();

MSTicket.Write(ContentByte,0, ContentByte.Length);byte[] ContentCryptByte =Crypt(MSTicket.ToArray(), Key);string ContentCryptStr =Encoding.ASCII.GetString(Base64Encode(ContentCryptByte));returnContentCryptStr;

}///

///方法说明 :解密方法///作者  :///完成日期 :///

/// 需要解密的密文内容

/// 解密密钥

/// 返回解密后明文字符串

public static string Decrypt(string content, stringsecret)

{if ((content == null) || (secret == null) || (content.Length == 0) || (secret.Length == 0))throw new ArgumentNullException("Invalid Argument");byte[] Key =GetKey(secret);byte[] CryByte =Base64Decode(Encoding.ASCII.GetBytes(content));byte[] DecByte =Decrypt(CryByte, Key);byte[] RealDecByte;stringRealDecStr;

RealDecByte=DecByte;byte[] Prefix = new byte[Constants.Operation.UnicodeReversePrefix.Length];

Array.Copy(RealDecByte, Prefix,2);if(CompareByteArrays(Constants.Operation.UnicodeReversePrefix, Prefix))

{byte SwitchTemp = 0;for (int i = 0; i < RealDecByte.Length - 1; i = i + 2)

{

SwitchTemp=RealDecByte[i];

RealDecByte[i]= RealDecByte[i + 1];

RealDecByte[i+ 1] =SwitchTemp;

}

}

RealDecStr=Encoding.Unicode.GetString(RealDecByte);returnRealDecStr;

}//使用TripleDES加密 ,三倍DES加密

public static byte[] Crypt(byte[] source, byte[] key)

{if ((source.Length == 0) || (source == null) || (key == null) || (key.Length == 0))

{throw new ArgumentException("Invalid Argument");

}

TripleDESCryptoServiceProvider dsp= newTripleDESCryptoServiceProvider();

dsp.Mode=CipherMode.ECB;

ICryptoTransform des= dsp.CreateEncryptor(key, null);return des.TransformFinalBlock(source, 0, source.Length);

}//使用TripleDES解密 来处理,三倍DES解密

public static byte[] Decrypt(byte[] source, byte[] key)

{if ((source.Length == 0) || (source == null) || (key == null) || (key.Length == 0))

{throw new ArgumentNullException("Invalid Argument");

}

TripleDESCryptoServiceProvider dsp= newTripleDESCryptoServiceProvider();

dsp.Mode=CipherMode.ECB;

ICryptoTransform des= dsp.CreateDecryptor(key, null);byte[] ret = new byte[source.Length + 8];intnum;

num= des.TransformBlock(source, 0, source.Length, ret, 0);

ret= des.TransformFinalBlock(source, 0, source.Length);

ret= des.TransformFinalBlock(source, 0, source.Length);

num=ret.Length;byte[] RealByte = new byte[num];

Array.Copy(ret, RealByte, num);

ret=RealByte;returnret;

}//原始base64编码

public static byte[] Base64Encode(byte[] source)

{if ((source == null) || (source.Length == 0))throw new ArgumentException("source is not valid");

ToBase64Transform tb64= newToBase64Transform();

MemoryStream stm= newMemoryStream();int pos = 0;byte[] buff;while (pos + 3

{

buff= tb64.TransformFinalBlock(source, pos, 3);

stm.Write(buff,0, buff.Length);

pos+= 3;

}

buff= tb64.TransformFinalBlock(source, pos, source.Length -pos);

stm.Write(buff,0, buff.Length);returnstm.ToArray();

}//原始base64解码

public static byte[] Base64Decode(byte[] source)

{if ((source == null) || (source.Length == 0))throw new ArgumentException("source is not valid");

FromBase64Transform fb64= newFromBase64Transform();

MemoryStream stm= newMemoryStream();int pos = 0;byte[] buff;while (pos + 4

{

buff= fb64.TransformFinalBlock(source, pos, 4);

stm.Write(buff,0, buff.Length);

pos+= 4;

}

buff= fb64.TransformFinalBlock(source, pos, source.Length -pos);

stm.Write(buff,0, buff.Length);returnstm.ToArray();

}/**

* 把密钥转化为2进制byte[] 如果大于 24byte就取前24位 作为 密钥

**/

public static byte[] GetKey(stringsecret)

{if ((secret == null) || (secret.Length == 0))throw new ArgumentException("Secret is not valid");byte[] temp;

ASCIIEncoding ae= newASCIIEncoding();

temp=Hash(ae.GetBytes(secret));byte[] ret = new byte[Constants.Operation.KeySize];inti;if (temp.Length

{

System.Array.Copy(temp,0, ret, 0, temp.Length);for (i = temp.Length; i < Constants.Operation.KeySize; i++)

{

ret[i]= 0;

}

}elseSystem.Array.Copy(temp,0, ret, 0, Constants.Operation.KeySize);returnret;

}//比较两个byte数组是否相同

public static bool CompareByteArrays(byte[] source, byte[] dest)

{if ((source == null) || (dest == null))throw new ArgumentException("source or dest is not valid");bool ret = true;if (source.Length !=dest.Length)return false;else

if (source.Length == 0)return true;for (int i = 0; i < source.Length; i++)if (source[i] !=dest[i])

{

ret= false;break;

}returnret;

}//使用md5计算散列

public static byte[] Hash(byte[] source)

{if ((source == null) || (source.Length == 0))throw new ArgumentException("source is not valid");

MD5 m=MD5.Create();returnm.ComputeHash(source);

}///

///对传入的明文密码进行Hash加密,密码不能为中文///

/// 需要加密的明文密码

/// 经过Hash加密的密码

public static string HashPassword(stringoriPassword)

{if (string.IsNullOrEmpty(oriPassword))throw new ArgumentException("oriPassword is valid");

ASCIIEncoding acii= newASCIIEncoding();byte[] hashedBytes =Hash(acii.GetBytes(oriPassword));

StringBuilder sb= new StringBuilder(30);foreach (byte b inhashedBytes)

{

sb.AppendFormat("{0:X2}", b);

}returnsb.ToString();

}public static string EncryptMd5(stringencode)

{return FormsAuthentication.HashPasswordForStoringInConfigFile(encode, "md5");

}const string m_strEncryptKey = "kingfykj";#region DES加密字符串

/

// 注意:密钥必须为8位/

///

///加密字符串///

/// 明码

/// 加密后的密码

public static string DesEncryptFixKey(stringp_strInput)

{byte[] byKey = null;byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};try{

byKey= System.Text.Encoding.UTF8.GetBytes(m_strEncryptKey.Substring(0, 8));

DESCryptoServiceProvider des= newDESCryptoServiceProvider();byte[] inputByteArray =Encoding.UTF8.GetBytes(p_strInput);

MemoryStream ms= newMemoryStream();

CryptoStream cs= newCryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);

cs.Write(inputByteArray,0, inputByteArray.Length);

cs.FlushFinalBlock();returnConvert.ToBase64String(ms.ToArray());

}catch(System.Exception ex)

{throw(ex);

}

}#endregion

#region DES解密字符串

//const string m_strEncryptKey = "kinghuns"; zh注释

///

///解密字符串///

/// 加了密的字符串

/// 密钥

public static string DesDecryptFixKey(stringp_strInput)

{byte[] byKey = null;byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};byte[] inputByteArray = newByte[p_strInput.Length];try{

byKey= System.Text.Encoding.UTF8.GetBytes(m_strEncryptKey.Substring(0, 8));

DESCryptoServiceProvider des= newDESCryptoServiceProvider();

inputByteArray=Convert.FromBase64String(p_strInput);

MemoryStream ms= newMemoryStream();

CryptoStream cs= newCryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);

cs.Write(inputByteArray,0, inputByteArray.Length);

cs.FlushFinalBlock();

System.Text.Encoding encoding= newSystem.Text.UTF8Encoding();returnencoding.GetString(ms.ToArray());

}catch(System.Exception ex)

{throw(ex);

}

}#endregion

//const string m_strEncryptKey = "kinghuns";

}///

///类名称 :Constants///类说明 :加解密算法常量.///作者 :///完成日期 :///

public classConstants

{public structOperation

{public static readonly int KeySize = 24;public static readonly byte[] UnicodeOrderPrefix = new byte[2] { 0xFF, 0xFE};public static readonly byte[] UnicodeReversePrefix = new byte[2] { 0xFE, 0xFF};

}

}

http://www.jmfq.cn/news/4915963.html

相关文章:

  • 电脑手机网站制作/防恶意竞价点击软件
  • 为什么不做网站做公众号/网络培训总结
  • 网站设计合同附件/服装店营销策划方案
  • 做通路富集分析的网站/关键词推广系统
  • wordpress 多站点迁移/重庆森林粤语完整版在线观看免费
  • 重庆网站建设公司/跨境电商培训机构哪个靠谱
  • 做优化网站注意什么/百度投诉中心24人工 客服电话
  • 江苏企业网站定制服务/怎样推广小程序平台
  • 2880元网站建设/百度游戏官网
  • 专业的培训行业网站制作/六种常见的网络广告类型
  • 淘宝的网站怎么做的好/爱站工具包官网
  • 怎么自己建一个论坛网站/哪个行业最需要推广
  • php做网站主要怎么布局/外包客服平台
  • 淘宝客网站建设难度大吗/域名解析ip地址查询
  • 网站扫码怎么做的/成都seo工程师
  • 做网站推广有效果吗/百度关键词优化
  • 魔方网站建设网站制作/网络营销策略的特点
  • 做网站是互联网开发吗/怎么做一个网页
  • 烟台做网站案例/如何做好一个网站
  • 如何做网站管理/江门seo外包公司
  • 网站编辑做app/投资网站建设方案
  • 网站建设报价东莞/每日新闻播报
  • 暖通设计网站推荐/谷歌seo详细教学
  • 网站建设佰金手指科杰十一/网络建站平台
  • 0基础做下载网站/优化大师是什么软件
  • 海口房产网站建设/长春做网站推荐选吉网传媒好
  • 手机做图片的网站/个人网站模板
  • 网站开发技术及特点/在线培训系统平台
  • wordpress 前台评论/优化法治化营商环境
  • 织梦移动端网站模板下载/网络推广山东