This document contains code for a program that can encrypt and decrypt input text. It imports necessary libraries and defines classes and methods for encryption and decryption. The program initializes an encryptor and decryptor using Rijndael encryption with a key and initialization vector. It has buttons to encrypt input text to base64 encoded ciphertext and decrypt ciphertext back to plaintext.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
19 views1 page
Encrypt
This document contains code for a program that can encrypt and decrypt input text. It imports necessary libraries and defines classes and methods for encryption and decryption. The program initializes an encryptor and decryptor using Rijndael encryption with a key and initialization vector. It has buttons to encrypt input text to base64 encoded ciphertext and decrypt ciphertext back to plaintext.
Me.encryptor = symmetricKey.CreateEncryptor(KEY_128, IV_128) Me.decryptor = symmetricKey.CreateDecryptor(KEY_128, IV_128) End Sub
Private Sub Button_Encrypt_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button_Encrypt.Click Dim sPlainText As String = Me.TextBox1.Text If Not String.IsNullOrEmpty(sPlainText) Then Dim memoryStream As MemoryStream = New MemoryStream() Dim cryptoStream As CryptoStream = New CryptoStream(memoryStream, Me.encryptor, CryptoStreamMode.Write) cryptoStream.Write(Me.enc.GetBytes(sPlainText), 0, sPlainText.Length) cryptoStream.FlushFinalBlock() Me.TextBox1.Text = Convert.ToBase64String(memoryStream.ToArray()) memoryStream.Close() cryptoStream.Close() End If End Sub
Private Sub Button_Decrypt_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button_Decrypt.Click Dim cypherTextBytes As Byte() = Convert.FromBase64String(Me.TextBox1.Text) Dim memoryStream As MemoryStream = New MemoryStream(cypherTextBytes) Dim cryptoStream As CryptoStream = New CryptoStream(memoryStream, Me.decryptor, CryptoStreamMode.Read) Dim plainTextBytes(cypherTextBytes.Length) As Byte Dim decryptedByteCount As Integer = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length) memoryStream.Close() cryptoStream.Close() Me.TextBox1.Text = Me.enc.GetString(plainTextBytes, 0, decryptedByteCount) End Sub End Class