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

How to analyze .NET C # DES

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Today, I will talk to you about how to analyze the .NET C # DES. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.

C # DES encryption should be the most basic encryption algorithm, in order to understand its use in .NET C #, I have made a lot of efforts, I hope people can see it. C # DES has a total of four parameters: plaintext, ciphertext, key, vector. For beginners to understand easily, the relationship of the four parameters can be written as: ciphertext = plaintext + key + vector; plaintext = ciphertext-key-vector. Why do you want the parameter vector? Because if there are several words repeated in an article, then the word plus the ciphertext formed by the key will still be repeated, which gives the cracker an opportunity to guess what the word is based on the repeated content, but once he guesses the word correctly, then, he can calculate the key, and the whole article will be cracked! After adding the parameter of vector, each text field will add a value in turn, so that even the same text and encrypted ciphertext are different, and the security of the algorithm is greatly improved.

The following application example of C# DES:

Using System; / / this is the basic using System.Security.Cryptography; of using DES / / this is the premise of processing text encoding using System.Text; / / processing text in the form of "stream", which is also the using System.IO required by Microsoft DES algorithm. / C # DES encryption method / plaintext / / key / / Vector / ciphertext public string DESEncrypt (string strPlain, string strDESKey,string strDESIV) {/ / convert the key to a byte array byte [] bytesDESKey=ASCIIEncoding.ASCII.GetBytes (strDESKey); / / convert the vector to a byte array byte [] bytesDESIV=ASCIIEncoding.ASCII.GetBytes (strDESIV) / declare a new DES object DESCryptoServiceProvider desEncrypt=new DESCryptoServiceProvider (); / / Open up a memory stream MemoryStream msEncrypt=new MemoryStream (); / / wrap the memory stream object as an encrypted stream object CryptoStream csEncrypt=new CryptoStream (msEncrypt,desEncrypt.CreateEncryptor (bytesDESKey,bytesDESIV), CryptoStreamMode.Write); / / wrap the encrypted stream object as a write stream object StreamWriter swEncrypt=new StreamWriter (csEncrypt); / / write the stream object to plaintext swEncrypt.WriteLine (strPlain) / / write stream closes swEncrypt.Close (); / / encrypt stream closes csEncrypt.Close (); / / converts memory stream to byte array, memory stream is now ciphertext byte [] bytesCipher=msEncrypt.ToArray (); / / memory stream closes msEncrypt.Close (); / / converts ciphertext byte array to string and returns return UnicodeEncoding.Unicode.GetString (bytesCipher) } / C # DES decryption method / ciphertext / key / / Vector / plaintext public string DESDecrypt (string strCipher, string strDESKey,string strDESIV) {/ / convert the key to a byte array byte [] bytesDESKey=ASCIIEncoding.ASCII.GetBytes (strDESKey); / / convert the vector to a byte array byte [] bytesDESIV=ASCIIEncoding.ASCII.GetBytes (strDESIV) / convert ciphertext to byte array byte [] bytesCipher=UnicodeEncoding.Unicode.GetBytes (strCipher); / declare a new DES object DESCryptoServiceProvider desDecrypt=new DESCryptoServiceProvider (); / / open up a memory stream and store the ciphertext byte array MemoryStream msDecrypt=new MemoryStream (bytesCipher); / / wrap the memory stream object as a decryption stream object CryptoStream csDecrypt=new CryptoStream (msDecrypt,desDecrypt.CreateDecryptor (bytesDESKey,bytesDESIV), CryptoStreamMode.Read) / / package the decryption stream object as a readout stream object StreamReader srDecrypt=new StreamReader (csDecrypt); / / plaintext = the readout content of the readout stream string strPlainText=srDecrypt.ReadLine (); / / read stream closes srDecrypt.Close (); / / decryption stream closes csDecrypt.Close (); / / memory stream closes msDecrypt.Close (); / / returns plaintext return strPlainText } after reading the above, do you have any further understanding of how to analyze the .NET C # DES? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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