0% found this document useful (0 votes)
3 views

eknripsi file dengan password

The document provides a guide for creating a file encryption and decryption project using password protection in Visual Basic. It includes detailed coding examples for the encryption (FrmEncrypt) and decryption (FrmDecrypt) forms, as well as a module (ModGen) for key generation. The instructions emphasize the importance of password validation and file handling during the encryption and decryption processes.
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
3 views

eknripsi file dengan password

The document provides a guide for creating a file encryption and decryption project using password protection in Visual Basic. It includes detailed coding examples for the encryption (FrmEncrypt) and decryption (FrmDecrypt) forms, as well as a module (ModGen) for key generation. The instructions emphasize the importance of password validation and file handling during the encryption and decryption processes.
Copyright
© © All Rights Reserved
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
You are on page 1/ 5

Enkripsi File Menggunakan Password

1. Buatlah Project dengan nama kamu !


2. Buatlah desain seperti di bawah ini :

Coding :

3. Buatlah desain seperti di bawah ini :

Coding :
Imports System.IO
Public Class FrmEncrypt

Private Sub CmdClose_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles CmdClose.Click
Application.Exit()
End Sub

Private Sub CmdBrowse_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles CmdBrowse.Click
Cd1.Filter = "Semua File|*.*"
Cd1.Title = "Pilih file yang akan dienkripsi."
Cd1.ShowDialog()
TxtFileName.Text = Cd1.FileName
End Sub

Private Sub CdmEncryption_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles CdmEncryption.Click
If File.Exists(TxtFileName.Text) = False Then
TxtFileName.SelectionStart = 0
TxtFileName.SelectionLength = TxtFileName.Text.Length
TxtFileName.Focus()
MsgBox("File tidak ada, pilih file yang akan di enkripsi.",
MsgBoxStyle.Exclamation)
Exit Sub
End If
If TxtPassword.Text = "" Then
TxtPassword.Focus()
MsgBox("Masukkan Password, password tidak boleh kosong.",
MsgBoxStyle.Exclamation)
Exit Sub
End If
If TxtPassword.Text <> TxtConfirmPassword.Text Then
TxtConfirmPassword.SelectionStart = 0
TxtConfirmPassword.SelectionLength = TxtConfirmPassword.Text.Length
TxtConfirmPassword.Focus()
MsgBox("Password and confirm password tidak cocok, coba lagi.",
MsgBoxStyle.Exclamation)
Exit Sub
End If
Dim DsImg As New DataSet
Dim Dt As New DataTable("Images")
Dt.Columns.Add(New DataColumn("sysid",
System.Type.GetType("System.String")))
Dt.Columns.Add(New DataColumn("filename",
System.Type.GetType("System.String")))
Dt.Columns.Add(New DataColumn("image",
System.Type.GetType("System.Byte[]")))
Dt.Columns.Add(New DataColumn("filetag",
System.Type.GetType("System.String")))
DsImg.Tables.Add(Dt)
Dim Fs As New System.IO.FileStream(TxtFileName.Text,
System.IO.FileMode.Open)
Dim bn As New System.IO.BinaryReader(Fs)
Dim Dr As DataRow
Dr = DsImg.Tables("images").NewRow
Dr("sysid") = Now.ToString
Dr("filename") = TxtFileName.Text
Dr("image") = bn.ReadBytes(Int(bn.BaseStream.Length))
Dr("filetag") = StrEncrypt(TxtPassword.Text)
DsImg.Tables("images").Rows.Add(Dr)
DsImg.WriteXml(TxtFileName.Text & ".sp2p")
MsgBox("Proses enkripsi selesai." & vbCrLf & vbCrLf & "File enkripsi baru
terbentuk sebagai..." & vbCrLf & TxtFileName.Text & ".sp2p",
MsgBoxStyle.Information)
End Sub

End Class
4. Buatlah desain seperti di bawah ini :

Coding :
Imports System.IO
Public Class FrmDecrypt
Private Sub CmdClose_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdClose.Click
Application.Exit()
End Sub

Private Sub CmdBrowse_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles CmdBrowse.Click
Cd1.Filter = "Secure p2p file|*.sp2p"
Cd1.Title = "Select *.sp2p file to decrypt."
Cd1.ShowDialog()
TxtFileName.Text = Cd1.FileName
End Sub
Private Sub CmdDecryption_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles CmdDecryption.Click
If File.Exists(TxtFileName.Text) = False Then
TxtFileName.SelectionStart = 0
TxtFileName.SelectionLength = TxtFileName.Text.Length
TxtFileName.Focus()
MsgBox("File tidak ada, pilih file yang akan di dekrip.",
MsgBoxStyle.Exclamation)
Exit Sub
End If
If TxtPassword.Text = "" Then
TxtPassword.Focus()
MsgBox("Masukkan password, password tidak boleh kosong.",
MsgBoxStyle.Exclamation)
Exit Sub
End If
Dim DsImg As New DataSet
Dim Dt As New DataTable("Images")
Dt.Columns.Add(New DataColumn("sysid",
System.Type.GetType("System.String")))
Dt.Columns.Add(New DataColumn("filename",
System.Type.GetType("System.String")))
Dt.Columns.Add(New DataColumn("image",
System.Type.GetType("System.Byte[]")))
Dt.Columns.Add(New DataColumn("filetag",
System.Type.GetType("System.String")))
DsImg.Tables.Add(Dt)
DsImg.ReadXml(TxtFileName.Text)
If TxtPassword.Text <>
StrDecrypt(DsImg.Tables(0).Rows(0).Item("filetag")) Then
TxtFileName.SelectionStart = 0
TxtPassword.SelectionLength = TxtPassword.Text.Length
TxtPassword.Focus()
MsgBox("Kode keamanan invalid, tidak dapat mendekripsi file",
MsgBoxStyle.Critical)
Exit Sub
End If
Dim FileName As String
FileName = Mid(TxtFileName.Text, 1, Len(TxtFileName.Text) - 5)
Dim Content As Byte()
Content = DsImg.Tables(0).Rows(0).Item(2)
Dim Fs As New System.IO.FileStream(FileName, System.IO.FileMode.Create)
Fs.Write(Content, 0, Content.Length)
Fs.Close()
MsgBox("Proses dekripsi selesai." & vbCrLf & vbCrLf & "File baru
terbentuk sebagai..." & vbCrLf & FileName, MsgBoxStyle.Information)
End Sub
End Class

5. Tambahkan module :

ModGen.vb
Coding :
Module ModGen
Const KeyPair As String = "Abt$9>3ZyX 21~)**1_0d%1xOp0#?s!14k-
L7`3s9cxPo1ilIj=-0DnmOpas#$%5854/*?>00021atanu???"

You might also like