Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '-----------------------------ENCRYPT
- Imports System.IO
- Imports System.Security.Cryptography
- Module Encrypt
- Sub EncryptText()
- Try
- Dim EncryptStream As New FileStream("C:\somePath\Test.txt", FileMode.Open)
- Dim RMCrypto As New RijndaelManaged()
- Dim key As Byte() = {&H1, &H2, &H3, &H4, &H5, &H6, &H7, &H8, &H9, &H10, &H11, &H12, &H13, &H14, &H15, &H16}
- Dim IV As Byte() = {&H1, &H2, &H3, &H4, &H5, &H6, &H7, &H8, &H9, &H10, &H11, &H12, &H13, &H14, &H15, &H16}
- Dim CryptStream As New CryptoStream(EncryptStream, RMCrypto.CreateEncryptor(key, IV), CryptoStreamMode.Write)
- Dim sWriter As New StreamWriter(CryptStream)
- sWriter.WriteLine(Form1.TextBox1.Text)
- MsgBox("The plaintext has been converted to ciphertext.", MsgBoxStyle.Information, "Encrypted Text")
- sWriter.Close()
- CryptStream.Close()
- EncryptStream.Close()
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Encrypting Error")
- End Try
- End Sub
- End Module
- '--------------------------DECRYPT
- Imports System.IO
- Imports System.Security.Cryptography
- Module Decrypt
- Sub Decyrpt()
- Dim key As Byte() = {&H1, &H2, &H3, &H4, &H5, &H6, &H7, &H8, &H9, &H10, &H11, &H12, &H13, &H14, &H15, &H16}
- Dim IV As Byte() = {&H1, &H2, &H3, &H4, &H5, &H6, &H7, &H8, &H9, &H10, &H11, &H12, &H13, &H14, &H15, &H16}
- Try
- Dim DecryptStream As New FileStream("C:\somePath\Test.txt", FileMode.OpenOrCreate)
- Dim RMCrypto As New RijndaelManaged()
- Dim CryptStream As New CryptoStream(DecryptStream, RMCrypto.CreateDecryptor(key, IV), CryptoStreamMode.Read)
- Dim sRead As New StreamReader(CryptStream)
- Form1.TextBox2.Text = String.Format("The plaintext is: {0} {1}", vbCrLf, sRead.ReadToEnd())
- sRead.Close()
- DecryptStream.Close()
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical, "Decrypting Error")
- End Try
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment