In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to understand the implementation of C#DES encryption and decryption. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
The realization of C # DES encryption and decryption. DES algorithm is a symmetric cryptosystem in cryptosystem, which is developed by IBM Company. Its core is that the length of the key is 56 bits, the plaintext is grouped according to 64 bits, and the ciphertext group is formed by replacing or exchanging the grouped plaintext group and the 56-bit key by bit.
Implementation example of encryption and decryption of C# DES:
Namespace of C # DES encryption and decryption:
Using System; using System.Security.Cryptography; using System.IO; using System.Text
C# DES encryption and decryption method:
/ / encryption method publicstring Encrypt (string pToEncrypt, string sKey) {DESCryptoServiceProvider des = new DESCryptoServiceProvider (); / / put the string in the byte array / / the original UTF8 encoding was changed to Unicode, not byte [] inputByteArray= Encoding.Default.GetBytes (pToEncrypt); / / byte [] inputByteArray=Encoding.Unicode.GetBytes (pToEncrypt)
C # DES encryption and decryption to establish the key and offset of the encrypted object
/ / the original text uses the GetBytes method of the ASCIIEncoding.ASCII method / / so that the input password must be des.Key = ASCIIEncoding.ASCII.GetBytes (sKey); des.IV = ASCIIEncoding.ASCII.GetBytes (sKey); MemoryStream ms = new MemoryStream (); CryptoStream cs = new CryptoStream (ms, des.CreateEncryptor (), CryptoStreamMode.Write) / / Write the byte array into the crypto stream / / (It will end up in the memory stream) cs.Write (inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock (); / / Get the data back from the memory stream, and into a string StringBuilder ret = new StringBuilder (); foreach (byte b in ms.ToArray ()) {/ / Format as hex ret.AppendFormat ("{0:X2}", b) } ret.ToString (); return ret.ToString ();}
Decryption method of encryption and decryption of C# DES
Publicstring Decrypt (string pToDecrypt, string sKey) {DESCryptoServiceProvider des = new DESCryptoServiceProvider (); / / Put the input string into the byte array 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;}
C # DES encryption and decryption to establish the key and offset of the encryption object. This value is important and cannot be modified.
Des.Key = ASCIIEncoding.ASCII.GetBytes (sKey); des.IV = ASCIIEncoding.ASCII.GetBytes (sKey); MemoryStream ms = new MemoryStream (); CryptoStream cs = new CryptoStream (ms, des.CreateDecryptor (), CryptoStreamMode.Write); / / Flush the data through the crypto stream into the memory stream cs.Write (inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock () / / Get the decrypted data back from the memory stream / / create a StringBuild object. / / CreateDecrypt uses a stream object, and the decrypted text must be changed into a stream object StringBuilder ret = new StringBuilder (); return System.Text.Encoding.Default.GetString (ms.ToArray ()) } on how to understand the implementation of C#DES encryption and decryption is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.