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 write DEC encryption Program by VB.NET

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

Share

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

This article mainly shows you "VB.NET how to write DEC encryption procedures", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "VB.NET how to write DEC encryption procedures" this article.

It is easy to write a DEC encryption program in VB.NET because the corresponding functions are included in VB.NET 's class library. Here are the encryption functions and decryption functions respectively.

Encryption function:

Public Shared Function Encrypt (ByVal pToEncrypt As String

ByVal sKey As String) As String

Dim des As New DESCryptoServiceProvider ()

Dim inputByteArray () As Byte

InputByteArray = Encoding.Default.GetBytes (pToEncrypt)

'' establish the key and offset of the encrypted object

'' make it necessary to enter a password in English

Des.Key = ASCIIEncoding.ASCII.GetBytes (sKey)

Des.IV = ASCIIEncoding.ASCII.GetBytes (sKey)

'' write a binary array to an encrypted stream

'' (write all the contents of the memory stream)

Dim ms As New System.IO.MemoryStream ()

Dim cs As New CryptoStream (ms, des.CreateEncryptor, CryptoStreamMode.Write)

'' write a binary array to an encrypted stream

'' (write all the contents of the memory stream)

Cs.Write (inputByteArray, 0, inputByteArray.Length)

Cs.FlushFinalBlock ()

'' create the output string

Dim ret As New StringBuilder ()

Dim b As Byte

For Each b In ms.ToArray ()

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

Next

Return ret.ToString ()

End Function

Decryption function:

Public Shared Function Decrypt (ByVal pToDecrypt As String

ByVal sKey As String) As String

Dim des As New DESCryptoServiceProvider ()

Dim len As Integer

Dim inputByteArray (len) As Byte

Dim x, i As Integer

For x = 0 To len

I = Convert.ToInt32 (pToDecrypt.Substring (x * 2,2), 16)

InputByteArray (x) = CType (I, Byte)

Next

'' establish the key and offset of the encrypted object, which is important and cannot be modified

Des.Key = ASCIIEncoding.ASCII.GetBytes (sKey)

Des.IV = ASCIIEncoding.ASCII.GetBytes (sKey)

Dim ms As New System.IO.MemoryStream ()

Dim cs As New CryptoStream (ms, des.CreateDecryptor

CryptoStreamMode.Write)

Cs.Write (inputByteArray, 0, inputByteArray.Length)

Cs.FlushFinalBlock ()

Return Encoding.Default.GetString (ms.ToArray)

End Function

The * parameters of the two functions are the string to be encrypted or decrypted. SKey is the key used and must be 8 bits. Be careful when using it, or you will make an error.

These are all the contents of the article "how to write DEC encryption programs in VB.NET". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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