SlideShare une entreprise Scribd logo
1  sur  5
Ketikkan Coding :
Imports Encryption.Crypto.Secret
Public Class Form1
'Reflects the index of the image
Private Enum Images
Encrypted = 0
Decrypted = 1
Folder_Open = 2
End Enum
#Region " Events"
#Region " Form Events"
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.btnEncrypt.Image = Me.ImageList1.Images(Images.Encrypted)
Me.btnDecrypt.Image = Me.ImageList1.Images(Images.Decrypted)
Me.btnOpenInput.Image = Me.ImageList1.Images(Images.Folder_Open)
Me.btnOpenOutput.Image = Me.ImageList1.Images(Images.Folder_Open)
End Sub
#End Region

'Form Events

#Region " Control Events"
Private Sub Open(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnOpenInput.Click
Dim btn As Button = DirectCast(sender, Button)
'The name of the TextBox to return the selected file path to is stored
' in the Tag property of the button.
Dim tb As TextBox = _
DirectCast(btn.Parent.Controls(btn.Tag.ToString()), TextBox)
Dim diag As New OpenFileDialog()
With diag
.CheckFileExists = True
.CheckPathExists = True
.Multiselect = False
.RestoreDirectory = True
.Title = "Please select an Input file"
.Filter = "All Files (*.*)|*.*"
.ShowDialog()
'Set the file path if one was selected
If .FileName.Trim() <> "" Then _
tb.Text = .FileName
End With
diag.Dispose()
End Sub

Private Sub Save(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnOpenOutput.Click
Dim btn As Button = DirectCast(sender, Button)
'The name of the TextBox to return the selected file path to is stored
' in the Tag property of the button.
Dim tb As TextBox = _
DirectCast(btn.Parent.Controls(btn.Tag.ToString()), TextBox)
Dim diag As New SaveFileDialog()
With diag
.AddExtension = True
.CheckFileExists = False
.CheckPathExists = True
.CreatePrompt = False
'Set the extension if there is an input file
If My.Computer.FileSystem.FileExists(Me.tbInput.Text.Trim()) = True Then
.DefaultExt = System.IO.Path.GetExtension(Me.tbInput.Text)
'Set the filter to whatever type of file was selected as an input file
.Filter = String.Concat(StrConv(.DefaultExt, VbStrConv.ProperCase), _
" Files (*.", .DefaultExt, ")|*.", .DefaultExt, _
"|All Files (*.*)|*.*")
Else
.Filter &= "All Files (*.*)|*.*"
End If
.OverwritePrompt = True
.RestoreDirectory = True
.Title = "Please enter an output file."
.ShowDialog()
If .FileName.Trim() <> "" Then _
tb.Text = .FileName
End With
diag.Dispose()
End Sub

Private Sub btnEncrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnEncrypt.Click
'Get the reference to the button that was clicked
Dim clickedButton As Button = DirectCast(sender, Button)
'Call the EncryptDecrypt method and pass to it the Button that was clicked
EncryptDecrypt(clickedButton)
MessageBox.Show("Encryption complete!", "Encryption complete", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Private Sub btnDecrypt_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnDecrypt.Click
'Get the reference to the button that was clicked
Dim clickedButton As Button = DirectCast(sender, Button)
'Call the EncryptDecrypt method and pass to it the Button that was clicked
EncryptDecrypt(clickedButton)
MessageBox.Show("Decryption complete!", "Decryption complete", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Private Sub lblWikiLink_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles lblWikiLink.Click
System.Diagnostics.Process.Start(Me.lblWikiLink.Text)
End Sub

Private Sub RadioButton_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles
rbAes.CheckedChanged, rbTripleDes.CheckedChanged, rbRijndael.CheckedChanged,
rbRc2.CheckedChanged, rbDes.CheckedChanged
Dim enc As Encryption.Crypto.Secret._BaseEncryption = _
GetEncryptor()

tbSecretEncryptorDesc.Text = enc.Description
End Sub
#End Region

'Control Events

#End Region

'Events

#Region " Methods"
Private Sub EncryptDecrypt(ByVal clickedButton As Button)
'Create a new instance of the _BaseEncryption class,
' and get the appropriate encryptor class
Dim enc As Encryption.Crypto.Secret._BaseEncryption = _
GetEncryptor()
'Encrypt or Decrypt the selected file.
' (This will call the corresponding method in the actual class)
If clickedButton.Text = "Encrypt" Then
enc.Encrypt(Me.tbInput.Text.Trim(), Me.tbOutput.Text.Trim())
ElseIf clickedButton.Text = "Decrypt" Then
enc.Decrypt(Me.tbInput.Text.Trim(), Me.tbOutput.Text.Trim())
End If
End Sub

Private Function GetEncryptor() As _BaseEncryption
Dim enc As Encryption.Crypto.Secret._BaseEncryption = Nothing
Dim wikiLink As String = String.Empty
'Set the _BaseEncryption class to the class corresponding to the RadioButton
' that was clicked
Select Case True
Case Me.rbAes.Checked
enc = AES.Create()
wikiLink = "http://en.wikipedia.org/wiki/Advanced_Encryption_Standard"
Case Me.rbDes.Checked
enc = DES.Create()
wikiLink = "http://en.wikipedia.org/wiki/Data_Encryption_Standard"
Case Me.rbRc2.Checked
enc = Rc2.Create()
wikiLink = "http://en.wikipedia.org/wiki/RC2"
Case Me.rbRijndael.Checked
enc = Rijndael.Create()
wikiLink = "http://en.wikipedia.org/wiki/Rijndael_encryption_algorithm"
Case Me.rbTripleDes.Checked
enc = TripleDes.Create()
wikiLink = "http://en.wikipedia.org/wiki/Triple_DES"
End Select
Me.lblWikiLink.Text = wikiLink
Return enc
End Function
#End Region
End Class

'Methods

Contenu connexe

Tendances

Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5sotlsoc
 
Código Opção Substituir
Código Opção SubstituirCódigo Opção Substituir
Código Opção Substituircymbron
 
Código Editor Net
Código Editor NetCódigo Editor Net
Código Editor Netcymbron
 
Creating Ext GWT Extensions and Components
Creating Ext GWT Extensions and ComponentsCreating Ext GWT Extensions and Components
Creating Ext GWT Extensions and ComponentsSencha
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandlingArati Gadgil
 
Código Acerca Editor_Net
Código Acerca Editor_NetCódigo Acerca Editor_Net
Código Acerca Editor_Netcymbron
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART IIIOXUS 20
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFQuang Nguyễn Bá
 
Código fuente del software educativo
Código fuente del software educativoCódigo fuente del software educativo
Código fuente del software educativoLeo Chavez Martinez
 
Ordenar vector
Ordenar vectorOrdenar vector
Ordenar vectorecasteloc
 
Código fuente del software educativo
Código fuente del software educativoCódigo fuente del software educativo
Código fuente del software educativoLeo Chavez Martinez
 

Tendances (18)

Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Trabajo de case
Trabajo de caseTrabajo de case
Trabajo de case
 
Código Opção Substituir
Código Opção SubstituirCódigo Opção Substituir
Código Opção Substituir
 
Código Editor Net
Código Editor NetCódigo Editor Net
Código Editor Net
 
Creating Ext GWT Extensions and Components
Creating Ext GWT Extensions and ComponentsCreating Ext GWT Extensions and Components
Creating Ext GWT Extensions and Components
 
Event handling in Java(part 2)
Event handling in Java(part 2)Event handling in Java(part 2)
Event handling in Java(part 2)
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
 
Trabajo de case
Trabajo de caseTrabajo de case
Trabajo de case
 
Código Acerca Editor_Net
Código Acerca Editor_NetCódigo Acerca Editor_Net
Código Acerca Editor_Net
 
Stop watch and array
Stop watch and arrayStop watch and array
Stop watch and array
 
Work flow
Work flowWork flow
Work flow
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
Lesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPFLesson 07 Actions and Commands in WPF
Lesson 07 Actions and Commands in WPF
 
Código fuente del software educativo
Código fuente del software educativoCódigo fuente del software educativo
Código fuente del software educativo
 
Ordenar vector
Ordenar vectorOrdenar vector
Ordenar vector
 
CRUD VB2010
CRUD VB2010CRUD VB2010
CRUD VB2010
 
Código fuente del software educativo
Código fuente del software educativoCódigo fuente del software educativo
Código fuente del software educativo
 

Similaire à Metode

Imports System.Net.Sockets Imports System.Text Public Class Form1 .pdf
  Imports System.Net.Sockets Imports System.Text Public Class Form1   .pdf  Imports System.Net.Sockets Imports System.Text Public Class Form1   .pdf
Imports System.Net.Sockets Imports System.Text Public Class Form1 .pdfapnashop1
 
Elementos del lenguaje
Elementos del lenguajeElementos del lenguaje
Elementos del lenguajeguest6473b8
 
1. Determine the output displayed when the button is clicked.Priva.docx
1. Determine the output displayed when the button is clicked.Priva.docx1. Determine the output displayed when the button is clicked.Priva.docx
1. Determine the output displayed when the button is clicked.Priva.docxcorbing9ttj
 
1. Determine the output displayed when the button is clicked. Priv.docx
1. Determine the output displayed when the button is clicked. Priv.docx1. Determine the output displayed when the button is clicked. Priv.docx
1. Determine the output displayed when the button is clicked. Priv.docxcorbing9ttj
 
Sistema de ventas
Sistema de ventasSistema de ventas
Sistema de ventasDAYANA RETO
 
Sistemadeventas 100707084319-phpapp01
Sistemadeventas 100707084319-phpapp01Sistemadeventas 100707084319-phpapp01
Sistemadeventas 100707084319-phpapp01mafv1976
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITYDOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITYGOKUL SREE
 
Ensayo Convergencia Informatica
Ensayo Convergencia InformaticaEnsayo Convergencia Informatica
Ensayo Convergencia Informaticamiguel camelo
 
C++ Windows Forms L10 - Instantiate
C++ Windows Forms L10 - InstantiateC++ Windows Forms L10 - Instantiate
C++ Windows Forms L10 - InstantiateMohammad Shaker
 
Inventory management
Inventory managementInventory management
Inventory managementRajeev Sharan
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVASrajan Shukla
 
Código fuente del software educativo
Código fuente del software educativoCódigo fuente del software educativo
Código fuente del software educativoLeo Chavez Martinez
 
Puerto serialarduino
Puerto serialarduinoPuerto serialarduino
Puerto serialarduinozadkiel_123
 

Similaire à Metode (20)

Docimp
DocimpDocimp
Docimp
 
Imports System.Net.Sockets Imports System.Text Public Class Form1 .pdf
  Imports System.Net.Sockets Imports System.Text Public Class Form1   .pdf  Imports System.Net.Sockets Imports System.Text Public Class Form1   .pdf
Imports System.Net.Sockets Imports System.Text Public Class Form1 .pdf
 
VB net lab.pdf
VB net lab.pdfVB net lab.pdf
VB net lab.pdf
 
Elementos del lenguaje
Elementos del lenguajeElementos del lenguaje
Elementos del lenguaje
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
1. Determine the output displayed when the button is clicked.Priva.docx
1. Determine the output displayed when the button is clicked.Priva.docx1. Determine the output displayed when the button is clicked.Priva.docx
1. Determine the output displayed when the button is clicked.Priva.docx
 
1. Determine the output displayed when the button is clicked. Priv.docx
1. Determine the output displayed when the button is clicked. Priv.docx1. Determine the output displayed when the button is clicked. Priv.docx
1. Determine the output displayed when the button is clicked. Priv.docx
 
Sistema de ventas
Sistema de ventasSistema de ventas
Sistema de ventas
 
Sistemadeventas 100707084319-phpapp01
Sistemadeventas 100707084319-phpapp01Sistemadeventas 100707084319-phpapp01
Sistemadeventas 100707084319-phpapp01
 
Colegio municipal
Colegio municipalColegio municipal
Colegio municipal
 
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITYDOT NET LAB PROGRAM PERIYAR UNIVERSITY
DOT NET LAB PROGRAM PERIYAR UNIVERSITY
 
Ensayo Convergencia Informatica
Ensayo Convergencia InformaticaEnsayo Convergencia Informatica
Ensayo Convergencia Informatica
 
Ete programs
Ete programsEte programs
Ete programs
 
Calculator code
Calculator codeCalculator code
Calculator code
 
C++ Windows Forms L10 - Instantiate
C++ Windows Forms L10 - InstantiateC++ Windows Forms L10 - Instantiate
C++ Windows Forms L10 - Instantiate
 
Inventory management
Inventory managementInventory management
Inventory management
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
Código fuente del software educativo
Código fuente del software educativoCódigo fuente del software educativo
Código fuente del software educativo
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
 
Puerto serialarduino
Puerto serialarduinoPuerto serialarduino
Puerto serialarduino
 

Dernier

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Dernier (20)

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Metode

  • 1. Ketikkan Coding : Imports Encryption.Crypto.Secret Public Class Form1 'Reflects the index of the image Private Enum Images Encrypted = 0 Decrypted = 1 Folder_Open = 2 End Enum
  • 2. #Region " Events" #Region " Form Events" Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Me.btnEncrypt.Image = Me.ImageList1.Images(Images.Encrypted) Me.btnDecrypt.Image = Me.ImageList1.Images(Images.Decrypted) Me.btnOpenInput.Image = Me.ImageList1.Images(Images.Folder_Open) Me.btnOpenOutput.Image = Me.ImageList1.Images(Images.Folder_Open) End Sub #End Region 'Form Events #Region " Control Events" Private Sub Open(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles btnOpenInput.Click Dim btn As Button = DirectCast(sender, Button) 'The name of the TextBox to return the selected file path to is stored ' in the Tag property of the button. Dim tb As TextBox = _ DirectCast(btn.Parent.Controls(btn.Tag.ToString()), TextBox) Dim diag As New OpenFileDialog() With diag .CheckFileExists = True .CheckPathExists = True .Multiselect = False .RestoreDirectory = True .Title = "Please select an Input file" .Filter = "All Files (*.*)|*.*" .ShowDialog() 'Set the file path if one was selected If .FileName.Trim() <> "" Then _ tb.Text = .FileName End With diag.Dispose() End Sub Private Sub Save(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnOpenOutput.Click Dim btn As Button = DirectCast(sender, Button) 'The name of the TextBox to return the selected file path to is stored ' in the Tag property of the button.
  • 3. Dim tb As TextBox = _ DirectCast(btn.Parent.Controls(btn.Tag.ToString()), TextBox) Dim diag As New SaveFileDialog() With diag .AddExtension = True .CheckFileExists = False .CheckPathExists = True .CreatePrompt = False 'Set the extension if there is an input file If My.Computer.FileSystem.FileExists(Me.tbInput.Text.Trim()) = True Then .DefaultExt = System.IO.Path.GetExtension(Me.tbInput.Text) 'Set the filter to whatever type of file was selected as an input file .Filter = String.Concat(StrConv(.DefaultExt, VbStrConv.ProperCase), _ " Files (*.", .DefaultExt, ")|*.", .DefaultExt, _ "|All Files (*.*)|*.*") Else .Filter &= "All Files (*.*)|*.*" End If .OverwritePrompt = True .RestoreDirectory = True .Title = "Please enter an output file." .ShowDialog() If .FileName.Trim() <> "" Then _ tb.Text = .FileName End With diag.Dispose() End Sub Private Sub btnEncrypt_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnEncrypt.Click 'Get the reference to the button that was clicked Dim clickedButton As Button = DirectCast(sender, Button) 'Call the EncryptDecrypt method and pass to it the Button that was clicked EncryptDecrypt(clickedButton) MessageBox.Show("Encryption complete!", "Encryption complete", _ MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub Private Sub btnDecrypt_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles btnDecrypt.Click 'Get the reference to the button that was clicked
  • 4. Dim clickedButton As Button = DirectCast(sender, Button) 'Call the EncryptDecrypt method and pass to it the Button that was clicked EncryptDecrypt(clickedButton) MessageBox.Show("Decryption complete!", "Decryption complete", _ MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub Private Sub lblWikiLink_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles lblWikiLink.Click System.Diagnostics.Process.Start(Me.lblWikiLink.Text) End Sub Private Sub RadioButton_CheckedChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles rbAes.CheckedChanged, rbTripleDes.CheckedChanged, rbRijndael.CheckedChanged, rbRc2.CheckedChanged, rbDes.CheckedChanged Dim enc As Encryption.Crypto.Secret._BaseEncryption = _ GetEncryptor() tbSecretEncryptorDesc.Text = enc.Description End Sub #End Region 'Control Events #End Region 'Events #Region " Methods" Private Sub EncryptDecrypt(ByVal clickedButton As Button) 'Create a new instance of the _BaseEncryption class, ' and get the appropriate encryptor class Dim enc As Encryption.Crypto.Secret._BaseEncryption = _ GetEncryptor() 'Encrypt or Decrypt the selected file. ' (This will call the corresponding method in the actual class) If clickedButton.Text = "Encrypt" Then enc.Encrypt(Me.tbInput.Text.Trim(), Me.tbOutput.Text.Trim()) ElseIf clickedButton.Text = "Decrypt" Then enc.Decrypt(Me.tbInput.Text.Trim(), Me.tbOutput.Text.Trim()) End If
  • 5. End Sub Private Function GetEncryptor() As _BaseEncryption Dim enc As Encryption.Crypto.Secret._BaseEncryption = Nothing Dim wikiLink As String = String.Empty 'Set the _BaseEncryption class to the class corresponding to the RadioButton ' that was clicked Select Case True Case Me.rbAes.Checked enc = AES.Create() wikiLink = "http://en.wikipedia.org/wiki/Advanced_Encryption_Standard" Case Me.rbDes.Checked enc = DES.Create() wikiLink = "http://en.wikipedia.org/wiki/Data_Encryption_Standard" Case Me.rbRc2.Checked enc = Rc2.Create() wikiLink = "http://en.wikipedia.org/wiki/RC2" Case Me.rbRijndael.Checked enc = Rijndael.Create() wikiLink = "http://en.wikipedia.org/wiki/Rijndael_encryption_algorithm" Case Me.rbTripleDes.Checked enc = TripleDes.Create() wikiLink = "http://en.wikipedia.org/wiki/Triple_DES" End Select Me.lblWikiLink.Text = wikiLink Return enc End Function #End Region End Class 'Methods