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

苏州网站建设方法网站页面设计策划书

苏州网站建设方法,网站页面设计策划书,天津建设工程信息网投标信息系统登录,做网站贵么前言 在我们日常开发工作中#xff0c;为了数据安全问题对数据加密、解密是必不可少的。加密方式有很多种如常见的AES#xff0c;RSA#xff0c;MD5#xff0c;SAH1#xff0c;SAH256#xff0c;DES等#xff0c;这时候假如我们有一个封装的对应加密解密工具类可以直接… 前言 在我们日常开发工作中为了数据安全问题对数据加密、解密是必不可少的。加密方式有很多种如常见的AESRSAMD5SAH1SAH256DES等这时候假如我们有一个封装的对应加密解密工具类可以直接调用那这样可以节省不少的开发时间。今天推荐一款实用的.NET Core加密解密工具类库NETCore.Encrypt。 项目介绍 NETCore.Encrypt是.NET Core加密解密工具类库包括AES、RSA、MD5、SHA1、DES、SHA256、SHA384、SHA512等更多功能。 项目源码 MD5加密 封装方法 #region MD5/// summary/// MD5 hash/// /summary/// param namesrcStringThe string to be encrypted./param/// param namelengthThe length of hash result , default value is see crefMD5Length.L32/./param/// returns/returnspublic static string Md5(string srcString, MD5Length length  MD5Length.L32){Check.Argument.IsNotEmpty(srcString, nameof(srcString));string str_md5_out  string.Empty;using (MD5 md5  MD5.Create()){byte[] bytes_md5_in  Encoding.UTF8.GetBytes(srcString);byte[] bytes_md5_out  md5.ComputeHash(bytes_md5_in);str_md5_out  length  MD5Length.L32? BitConverter.ToString(bytes_md5_out): BitConverter.ToString(bytes_md5_out, 4, 8);str_md5_out  str_md5_out.Replace(-, );return str_md5_out;}}#endregion调用结果 public static void MD5_Test(){var srcString  追逐时光者;var hashed  EncryptProvider.Md5(srcString);Console.WriteLine(MD5加密结果  hashed);}RSA加密解密 封装方法 /// summary/// RSA encrypt/// /summary/// param namepublicKeypublic key/param/// param namesrcStringsrc string/param/// param namepaddingrsa encryptPadding see crefRSAEncryptionPadding/ RSAEncryptionPadding.Pkcs1 for linux/mac openssl /param/// param nameisPemKeyset key is pem format,default is false/param/// returnsencrypted string/returnspublic static string RSAEncrypt(string publicKey, string srcString, RSAEncryptionPadding padding, bool isPemKey  false){Check.Argument.IsNotEmpty(publicKey, nameof(publicKey));Check.Argument.IsNotEmpty(srcString, nameof(srcString));Check.Argument.IsNotNull(padding, nameof(padding));RSA rsa;if (isPemKey){rsa  RsaProvider.FromPem(publicKey);}else{rsa  RSA.Create();rsa.FromJsonString(publicKey);}using (rsa){var maxLength  GetMaxRsaEncryptLength(rsa, padding);var rawBytes  Encoding.UTF8.GetBytes(srcString);if (rawBytes.Length  maxLength){throw new OutofMaxlengthException(${srcString} is out of max encrypt length {maxLength}, maxLength, rsa.KeySize, padding);}byte[] encryptBytes  rsa.Encrypt(rawBytes, padding);return encryptBytes.ToHexString();}}/// summary/// RSA decrypt/// /summary/// param namepublicKeypublic key/param/// param namesrcStringsrc string/param/// param namepaddingrsa encryptPadding see crefRSAEncryptionPadding/ RSAEncryptionPadding.Pkcs1 for linux/mac openssl /param/// param nameisPemKeyset key is pem format,default is false/param/// returnsencrypted string/returnspublic static string RSADecrypt(string privateKey, string srcString, RSAEncryptionPadding padding, bool isPemKey  false){Check.Argument.IsNotEmpty(privateKey, nameof(privateKey));Check.Argument.IsNotEmpty(srcString, nameof(srcString));Check.Argument.IsNotNull(padding, nameof(padding));RSA rsa;if (isPemKey){rsa  RsaProvider.FromPem(privateKey);}else{rsa  RSA.Create();rsa.FromJsonString(privateKey);}using (rsa){byte[] srcBytes  srcString.ToBytes();byte[] decryptBytes  rsa.Decrypt(srcBytes, padding);return Encoding.UTF8.GetString(decryptBytes);}} 调用结果 #region Rsa加密解密public static void Rsa_Encrypt_Decrypt_Test(RsaSize size){var rsaKey  EncryptProvider.CreateRsaKey(size);var srcString  追逐时光者;var encrypted  EncryptProvider.RSAEncrypt(rsaKey.PublicKey, srcString);Console.WriteLine(RSA加密结果  encrypted);Console.WriteLine(\r\n);var decrypted  EncryptProvider.RSADecrypt(rsaKey.PrivateKey, encrypted);Console.WriteLine(RSA解密结果  decrypted);}#endregionDES加密解密 封装方法 /// summary/// DES encrypt/// /summary/// param namedataRaw data byte array/param/// param namekeyKey, requires 24 bits/param/// param namevectorIV,requires 8 bits/param/// returnsEncrypted byte array/returnspublic static byte[] DESEncrypt(byte[] data, string key, string vector){Check.Argument.IsNotEmpty(data, nameof(data));Check.Argument.IsNotEmpty(key, nameof(key));Check.Argument.IsEqualLength(key.Length, 24, nameof(key));Check.Argument.IsNotEmpty(vector, nameof(vector));Check.Argument.IsEqualLength(vector.Length, 8, nameof(vector));return DESEncrypt(data, key, CipherMode.CBC, vector);}/// summary/// DES encrypt/// /summary/// param namedataRaw data/param/// param namekeyKey, requires 24 bits/param/// param namecipherModesee crefCipherMode//param/// param namepaddingModesee crefPaddingMode/ default is PKCS7/param/// param namevectorIV,requires 8 bits/param/// returnsEncrypted byte array/returnsprivate static byte[] DESEncrypt(byte[] data, string key, CipherMode cipherMode, string vector  , PaddingMode paddingMode  PaddingMode.PKCS7){Check.Argument.IsNotEmpty(data, nameof(data));Check.Argument.IsNotEmpty(key, nameof(key));Check.Argument.IsEqualLength(key.Length, 24, nameof(key));using (MemoryStream Memory  new MemoryStream()){using (TripleDES des  TripleDES.Create()){byte[] plainBytes  data;byte[] bKey  new byte[24];Array.Copy(Encoding.UTF8.GetBytes(key.PadRight(bKey.Length)), bKey, bKey.Length);des.Mode  cipherMode;des.Padding  paddingMode;des.Key  bKey;if (cipherMode  CipherMode.CBC){byte[] bVector  new byte[8];Array.Copy(Encoding.UTF8.GetBytes(vector.PadRight(bVector.Length)), bVector, bVector.Length);des.IV  bVector;}using (CryptoStream cryptoStream  new CryptoStream(Memory, des.CreateEncryptor(), CryptoStreamMode.Write)){try{cryptoStream.Write(plainBytes, 0, plainBytes.Length);cryptoStream.FlushFinalBlock();return Memory.ToArray();}catch (Exception ex){return null;}}}}}/// summary/// DES encrypt/// /summary/// param namedataRaw data byte array/param/// param namekeyKey, requires 24 bits/param/// param namevectorIV,requires 8 bits/param/// returnsEncrypted byte array/returnspublic static byte[] DESDecrypt(byte[] data, string key, string vector){Check.Argument.IsNotEmpty(data, nameof(data));Check.Argument.IsNotEmpty(key, nameof(key));Check.Argument.IsEqualLength(key.Length, 24, nameof(key));Check.Argument.IsNotEmpty(vector, nameof(vector));Check.Argument.IsEqualLength(vector.Length, 8, nameof(vector));return DESDecrypt(data, key, CipherMode.CBC, vector);}/// summary/// DES decrypt/// /summary/// param namedataEncrypted data/param/// param namekeyKey, requires 24 bits/param/// param namecipherModesee crefCipherMode//param/// param namepaddingModesee crefPaddingMode/ default is PKCS7/param/// returnsDecrypted byte array/returnsprivate static byte[] DESDecrypt(byte[] data, string key, CipherMode cipherMode, string vector  , PaddingMode paddingMode  PaddingMode.PKCS7){Check.Argument.IsNotEmpty(data, nameof(data));Check.Argument.IsNotEmpty(key, nameof(key));Check.Argument.IsEqualLength(key.Length, 24, nameof(key));byte[] encryptedBytes  data;byte[] bKey  new byte[24];Array.Copy(Encoding.UTF8.GetBytes(key.PadRight(bKey.Length)), bKey, bKey.Length);using (MemoryStream Memory  new MemoryStream(encryptedBytes)){using (TripleDES des  TripleDES.Create()){des.Mode  cipherMode;des.Padding  paddingMode;des.Key  bKey;if (cipherMode  CipherMode.CBC){byte[] bVector  new byte[8];Array.Copy(Encoding.UTF8.GetBytes(vector.PadRight(bVector.Length)), bVector, bVector.Length);des.IV  bVector;}using (CryptoStream cryptoStream  new CryptoStream(Memory, des.CreateDecryptor(), CryptoStreamMode.Read)){try{byte[] tmp  new byte[encryptedBytes.Length];int len  cryptoStream.Read(tmp, 0, encryptedBytes.Length);byte[] ret  new byte[len];Array.Copy(tmp, 0, ret, 0, len);return ret;}catch{return null;}}}}}调用结果 #region DES加密解密public static void DES_Encrypt_Decrypt_Test(){var srcString  TEST DES Encrypt Decrypt;string key  EncryptProvider.CreateDesKey();string iv  EncryptProvider.CreateDesIv();var srsDatas  Encoding.UTF8.GetBytes(srcString);var encrypted  EncryptProvider.DESEncrypt(srsDatas, key, iv);Console.WriteLine(DES加密结果  encrypted); Console.WriteLine(\r\n);var decrypted  EncryptProvider.DESDecrypt(encrypted, key, iv);var decryptedStr  Encoding.UTF8.GetString(decrypted);Console.WriteLine(DES解密结果  decryptedStr);}#endregionAES加密解密 封装方法 /// summary/// AES encrypt ( no IV)/// /summary/// param namedataRaw data/param/// param namekeyKey, requires 32 bits/param/// returnsEncrypted string/returnspublic static string AESEncrypt(string data, string key){Check.Argument.IsNotEmpty(data, nameof(data));Check.Argument.IsNotEmpty(key, nameof(key));Check.Argument.IsEqualLength(key.Length, 32, nameof(key));using (MemoryStream memory  new MemoryStream()){using (Aes aes  Aes.Create()){byte[] plainBytes  Encoding.UTF8.GetBytes(data);byte[] bKey  new byte[32];Array.Copy(Encoding.UTF8.GetBytes(key.PadRight(bKey.Length)), bKey, bKey.Length);aes.Mode  CipherMode.ECB;aes.Padding  PaddingMode.PKCS7;aes.KeySize  256;aes.Key  bKey;using (CryptoStream cryptoStream  new CryptoStream(memory, aes.CreateEncryptor(), CryptoStreamMode.Write)){try{cryptoStream.Write(plainBytes, 0, plainBytes.Length);cryptoStream.FlushFinalBlock();return Convert.ToBase64String(memory.ToArray());}catch (Exception ex){return null;}}}}}/// summary/// AES decrypt( no IV)/// /summary/// param namedataEncrypted data/param/// param namekeyKey, requires 32 bits/param/// returnsDecrypted string/returnspublic static string AESDecrypt(string data, string key){Check.Argument.IsNotEmpty(data, nameof(data));Check.Argument.IsNotEmpty(key, nameof(key));Check.Argument.IsEqualLength(key.Length, 32, nameof(key));byte[] encryptedBytes  Convert.FromBase64String(data);byte[] bKey  new byte[32];Array.Copy(Encoding.UTF8.GetBytes(key.PadRight(bKey.Length)), bKey, bKey.Length);try{byte[] decryptedData  null; // decrypted datausing (MemoryStream memory  new MemoryStream(encryptedBytes)){using (Aes aes  Aes.Create()){aes.Mode  CipherMode.ECB;aes.Padding  PaddingMode.PKCS7;aes.KeySize  256;aes.Key  bKey;using (CryptoStream decryptor  new CryptoStream(memory, aes.CreateDecryptor(), CryptoStreamMode.Read)){using (MemoryStream tempMemory  new MemoryStream()){byte[] buffer  new byte[1024];Int32 readBytes  0;while ((readBytes  decryptor.Read(buffer, 0, buffer.Length))  0){tempMemory.Write(buffer, 0, readBytes);}decryptedData  tempMemory.ToArray();return Encoding.UTF8.GetString(decryptedData);}}}}}catch{return null;}}调用结果 #region AES加密解密public static void Aes_Encrypt_Decrypt_Test(){var aesKey  EncryptProvider.CreateAesKey();var key  aesKey.Key;var srcString  追逐时光者;var encrypted  EncryptProvider.AESEncrypt(srcString, key);Console.WriteLine(AES加密结果  encrypted);Console.WriteLine(\r\n);var decrypted  EncryptProvider.AESDecrypt(encrypted, key);Console.WriteLine(AES解密结果  decrypted);}#endregion项目源码地址 更多项目实用功能和特性欢迎前往项目开源地址查看别忘了给项目一个Star支持。 https://github.com/myloveCc/NETCore.Encrypt 优秀项目和框架精选 该项目已收录到C#/.NET/.NET Core优秀项目和框架精选中关注优秀项目和框架精选能让你及时了解C#、.NET和.NET Core领域的最新动态和最佳实践提高开发工作效率和质量。坑已挖欢迎大家踊跃提交PR推荐或自荐让优秀的项目和框架不被埋没。 https://github.com/YSGStudyHards/DotNetGuide/blob/main/docs/DotNet/DotNetProjectPicks.md
http://www.pierceye.com/news/430547/

相关文章:

  • 网站的虚拟主机到期延吉建设局网站
  • 深圳seo网站优化公司wordpress页面权限插件
  • 手机制作购物网站农业 网站源码
  • 飞沐网站设计成都推广网站多少钱
  • 网站建设需要什么手续秦皇岛市房价
  • seo织梦网站建设步骤西宁网络公司电话
  • 河南省建设厅网站 吴浩石家庄做外贸网站建设
  • 免费网站发布怎么做的校园网站建设的参考文献
  • 网站空间管理平台腾讯会议多少钱一个月
  • 手机网站开发如何设置触摸功能的网页设计培训班
  • 淘宝客自己做网站中信建设有限责任公司 闫励
  • wordpress 分页不出来昆明网站快速优化排名
  • 玉泉路网站制作369网站建设中心
  • 服务器建设网站办一家建筑公司怎么样
  • 官网网站设计小程序免费制作流程
  • 宜昌哪有有做网站的wordpress如何添加页面子目录
  • 高端网站制作开发html写一个简单购物页面
  • 为什么百度搜索不到我的网站网站服务商排名
  • 深圳建设网站首页国土 住房与城乡建设部网站
  • wordpress拖拽式建站主题wordpress 类似软件
  • ps制作网站logo广西建设局网站
  • 专业网站建设公司排名wordpress上传媒体文件大小修改
  • 郑州app开发公司排名网站seo 文章转载 修改标题
  • 深圳网站备案查询成都建设施工安全协会网站
  • 做视频找素材的网站有哪些邢台做网站多少钱
  • 创世网站建设公司设计理念页面设计
  • 免费的网站模板昆明装饰企业网络推广
  • 怎样用微信做购物网站广州菜谱制作公司
  • 视频网站发展好应该怎么做wordpress移动支付免费
  • 青岛网站设计案例wordpress 转换成小程序