Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of DES encryption and decryption MD5 in ASP.NET

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the example analysis of DES encryption and decryption MD5 in ASP.NET, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

Public class TrialHelper {/ / default key vector private static byte [] Keys = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF} / / DES encrypted string / / string to be encrypted / / encryption key, which requires the encrypted string to be returned for 8-bit / encryption If failed, the source string public static string EncryptDES (string encryptString, string encryptKey = "") {try {if (string.IsNullOrEmpty (encryptKey) | | encryptKey.Length < 8) {encryptKey = "winform01" is returned. } byte [] rgbKey = Encoding.UTF8.GetBytes (encryptKey.Substring (0,8)); byte [] rgbIV = Keys; byte [] inputByteArray = Encoding.UTF8.GetBytes (encryptString); DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider (); MemoryStream mStream = new MemoryStream (); CryptoStream cStream = new CryptoStream (mStream, dCSP.CreateEncryptor (rgbKey, rgbIV), CryptoStreamMode.Write); cStream.Write (inputByteArray, 0, inputByteArray.Length) CStream.FlushFinalBlock (); return Convert.ToBase64String (mStream.ToArray ());} catch {return encryptString }} / DES decryption string / the string to be decrypted / the decryption key is required to be 8 bits, which is the same as the encryption key. / the decrypted string is returned after successful decryption. Public static string DecryptDES (string decryptString, string decryptKey = "") {try {if (string.IsNullOrEmpty (decryptKey) | | decryptKey.Length < 8) {decryptKey = "winform01" } byte [] rgbKey = Encoding.UTF8.GetBytes (decryptKey.Substring (0,8)); byte [] rgbIV = Keys; byte [] inputByteArray = Convert.FromBase64String (decryptString); DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider (); MemoryStream mStream = new MemoryStream (); CryptoStream cStream = new CryptoStream (mStream, DCSP.CreateDecryptor (rgbKey, rgbIV), CryptoStreamMode.Write); cStream.Write (inputByteArray, 0, inputByteArray.Length) CStream.FlushFinalBlock (); return Encoding.UTF8.GetString (mStream.ToArray ());} catch {return decryptString } / MD5 data encryption / encrypted field / encrypted string public static string GetMD5 (string sDataIn) {System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider (); byte [] bytValue, bytHash; bytValue = System.Text.Encoding.UTF8.GetBytes (sDataIn); bytHash = md5.ComputeHash (bytValue) Md5.Clear (); string sTemp = ""; for (int I = 0; I < bytHash.Length; iTunes +) {sTemp + = bytHash.ToString ("x"). PadLeft (2,'0');} return sTemp;}}

Call:

/ / get login information loginRecord.Name = tbName.Text.Trim (); loginRecord.MD5Pwd = TrialHelper.GetMD5 (tbPwd.Password); / / Save to database MD5 encryption method loginRecord.Pwd = TrialHelper.EncryptDES (tbPwd.Password) / / remember the password des encryption method, save to the local thank you for reading this article carefully, hope that the editor to share the "ASP.NET DES encryption and decryption MD5 example analysis" this article is helpful to you, but also hope that you support a lot, pay attention to the industry information channel, more related knowledge waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report