vb.net文本加密与解密代码
使用VB.NET进行文本的加密保存,VB.NET中自带的源代码不会用,看不懂,有人解释下吗?Imports System.IO
Imports System.Security.Cryptography
TextBox1.Font = New System.Drawing.Font("Symbol", CType(9, Byte))
Dim fStream As FileStream = File.Open("encrypted.txt", FileMode.OpenOrCreate)
Dim RijndaelAlg As Rijndael = Rijndael.Create
Dim cStream As New CryptoStream(fStream, _
RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV), _
CryptoStreamMode.Write)
Dim sWriter As New StreamWriter(cStream)
sWriter.WriteLine("Text to encrypt")
sWriter.Close()
cStream.Close()
fStream.Close()
还有解密的:
TextBox1.Font = New System.Drawing.Font("宋体", CType(9, Byte))
Dim fStream As FileStream = File.Open("encrypted.txt", FileMode.OpenOrCreate)
Dim RijndaelAlg As Rijndael = Rijndael.Create
Dim cStream As New CryptoStream(fStream, _
RijndaelAlg.CreateDecryptor(RijndaelAlg.Key, RijndaelAlg.IV), _
CryptoStreamMode.Read)
Dim sReader As New StreamReader(cStream)
Dim plainText As String = sReader.ReadLine()
sReader.Close()
cStream.Close()
fStream.Close()