Metode
-
Upload
hendra-sinaga -
Category
Education
-
view
180 -
download
0
description
Transcript of Metode
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 'Methods
End Class