Ok nih pagi hari ini saya akan menshare kan contoh penggunaan kriptografi untuk mengamankan data yang akan tersimpan ke dalam record yang terdapat pada database. Contoh berikut menggunakan Kriptografi Caesar, Sederhana, Mudah dan Terkenal.
Anda ingin tahu beda Tanpa Kriptografi dengan menggunakan Kriptografi? Lihat saja gambar berikut ini :
Tabel berikut ini tanpa kriptografi
Anda ingin tahu beda Tanpa Kriptografi dengan menggunakan Kriptografi? Lihat saja gambar berikut ini :
Tabel berikut ini tanpa kriptografi
Saya jamin anda pasti bisa dengan mudah memahami data diatas tersebut bukan?
coba anda pahami data pada gambar berikut
coba anda pahami data pada gambar berikut
Tabel tersebut diatas setelah memakai kriptografi
Bagaimana? ingin tahu cara membuatnya? silahkan ikuti penerapan kriptografi pada record database menggunakan program VB NET
Terlebih dahulu buatlah database Nasabah.MDB dengan struktur tabel seperti berikut ini :
Tabel : Nasabah
Field Tipe Size
------------------------------
Kode Text 5
Nama Text 50
Alamat Text 100
Telp Text 15
Simpan pada drive C:
Kemudian silahkan design form nasabah seperti tampilan berikut ini.
Bagaimana? ingin tahu cara membuatnya? silahkan ikuti penerapan kriptografi pada record database menggunakan program VB NET
Terlebih dahulu buatlah database Nasabah.MDB dengan struktur tabel seperti berikut ini :
Tabel : Nasabah
Field Tipe Size
------------------------------
Kode Text 5
Nama Text 50
Alamat Text 100
Telp Text 15
Simpan pada drive C:
Kemudian silahkan design form nasabah seperti tampilan berikut ini.
Penerapan Kriptografi Pada Record Database Menggunakan Program VB NET
Imports System.Data.OleDb
Public Class Form1
Public DB As OleDbConnection
Public CMD As OleDbCommand
Public DR As OleDbDataReader
Public DS As New DataSet
Public SQL As String
Function ENCCaesar(ByVal Plain As String) As String
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Plain)
x = Mid(Plain, i, i)
x = Chr(Asc(x) + 3)
xkalimat = xkalimat + x
Next
ENCCaesar = xkalimat
End Function
Function DECCaesar(ByVal Chiper As String) As String
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Chiper)
x = Mid(Chiper, i, i)
x = Chr(Asc(x) - 3)
xkalimat = xkalimat + x
Next
DECCaesar = xkalimat
End Function
Public Sub OPENDB()
Dim LOKASI = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:Nasabah.mdb"
DB = New OleDbConnection(LOKASI)
If DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub
Sub TombolBaru()
btnBaru.Enabled = True
btnSimpan.Enabled = False
btnEdit.Enabled = False
btnHapus.Enabled = False
btnBatal.Enabled = False
btnKeluar.Enabled = True
End Sub
Sub TombolEdit()
btnBaru.Enabled = False
btnSimpan.Enabled = False
btnEdit.Enabled = True
btnHapus.Enabled = True
btnBatal.Enabled = True
btnKeluar.Enabled = False
End Sub
Sub TombolSimpan()
btnBaru.Enabled = False
btnSimpan.Enabled = True
btnEdit.Enabled = False
btnHapus.Enabled = False
btnBatal.Enabled = True
btnKeluar.Enabled = False
End Sub
Sub HapusForm()
Kode.Text = ""
Nama.Text = ""
Alamat.Text = ""
Telp.Text = ""
Call TombolBaru()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call OPENDB()
Call HapusForm()
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
SQL = "INSERT INTO Nasabah(Kode, Nama, Alamat, Telp)" & _
"Values (`" & Kode.Text & "`,`" & _
ENCCaesar(Nama.Text) & "`,`" & _
ENCCaesar(Alamat.Text) & "`,`" & _
ENCCaesar(Telp.Text) & "`)"
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call btnBaru_Click(sender, e)
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
SQL = "UPDATE Nasabah SET Nama=`" & ENCCaesar(Nama.Text) & "`, " & _
" Alamat=`" & ENCCaesar(Alamat.Text) & "`, " & _
" Telp=`" & ENCCaesar(Telp.Text) & "` " & _
" Where Kode=`" & Kode.Text & "`"
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call btnBaru_Click(sender, e)
End Sub
Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
SQL = "DELETE FROM Nasabah Where Kode=`" & Kode.Text & "`"
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call btnBaru_Click(sender, e)
End Sub
Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Call btnBaru_Click(sender, e)
End Sub
Private Sub btnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaru.Click
Call HapusForm()
Kode.Focus()
End Sub
Private Sub Kode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Kode.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
Dim xkode As String
If tombol = 13 Then
` Gunakan T pada SELEC
SQL = "SELEC * FROM Nasabah Where Kode=`" & Kode.Text & "`"
CMD = New OleDbCommand(SQL, DB)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows = True Then
Nama.Text = DECCaesar(DR("Nama"))
Alamat.Text = DECCaesar(DR("Alamat"))
Telp.Text = DECCaesar(DR("Telp"))
Call TombolEdit()
MsgBox("Data Ini Sudah Tersimpan Pada Tabel Nasabah !")
Else
xkode = Kode.Text
Call HapusForm()
Kode.Text = xkode
Call TombolSimpan()
End If
DR.Close()
Nama.Focus()
End If
End Sub
End Class
Hasil Program penerapan kriptografi pada record database menggunakan program VB NET.
Screen Pertama
Sewaktu data disearching maka record asli masih nampak, tanpa dilakukan Dekripsi
Imports System.Data.OleDb
Public Class Form1
Public DB As OleDbConnection
Public CMD As OleDbCommand
Public DR As OleDbDataReader
Public DS As New DataSet
Public SQL As String
Function ENCCaesar(ByVal Plain As String) As String
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Plain)
x = Mid(Plain, i, i)
x = Chr(Asc(x) + 3)
xkalimat = xkalimat + x
Next
ENCCaesar = xkalimat
End Function
Function DECCaesar(ByVal Chiper As String) As String
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Chiper)
x = Mid(Chiper, i, i)
x = Chr(Asc(x) - 3)
xkalimat = xkalimat + x
Next
DECCaesar = xkalimat
End Function
Public Sub OPENDB()
Dim LOKASI = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source=C:Nasabah.mdb"
DB = New OleDbConnection(LOKASI)
If DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub
Sub TombolBaru()
btnBaru.Enabled = True
btnSimpan.Enabled = False
btnEdit.Enabled = False
btnHapus.Enabled = False
btnBatal.Enabled = False
btnKeluar.Enabled = True
End Sub
Sub TombolEdit()
btnBaru.Enabled = False
btnSimpan.Enabled = False
btnEdit.Enabled = True
btnHapus.Enabled = True
btnBatal.Enabled = True
btnKeluar.Enabled = False
End Sub
Sub TombolSimpan()
btnBaru.Enabled = False
btnSimpan.Enabled = True
btnEdit.Enabled = False
btnHapus.Enabled = False
btnBatal.Enabled = True
btnKeluar.Enabled = False
End Sub
Sub HapusForm()
Kode.Text = ""
Nama.Text = ""
Alamat.Text = ""
Telp.Text = ""
Call TombolBaru()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call OPENDB()
Call HapusForm()
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
SQL = "INSERT INTO Nasabah(Kode, Nama, Alamat, Telp)" & _
"Values (`" & Kode.Text & "`,`" & _
ENCCaesar(Nama.Text) & "`,`" & _
ENCCaesar(Alamat.Text) & "`,`" & _
ENCCaesar(Telp.Text) & "`)"
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call btnBaru_Click(sender, e)
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
SQL = "UPDATE Nasabah SET Nama=`" & ENCCaesar(Nama.Text) & "`, " & _
" Alamat=`" & ENCCaesar(Alamat.Text) & "`, " & _
" Telp=`" & ENCCaesar(Telp.Text) & "` " & _
" Where Kode=`" & Kode.Text & "`"
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call btnBaru_Click(sender, e)
End Sub
Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
SQL = "DELETE FROM Nasabah Where Kode=`" & Kode.Text & "`"
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call btnBaru_Click(sender, e)
End Sub
Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Call btnBaru_Click(sender, e)
End Sub
Private Sub btnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaru.Click
Call HapusForm()
Kode.Focus()
End Sub
Private Sub Kode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Kode.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
Dim xkode As String
If tombol = 13 Then
` Gunakan T pada SELEC
SQL = "SELEC * FROM Nasabah Where Kode=`" & Kode.Text & "`"
CMD = New OleDbCommand(SQL, DB)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows = True Then
Nama.Text = DECCaesar(DR("Nama"))
Alamat.Text = DECCaesar(DR("Alamat"))
Telp.Text = DECCaesar(DR("Telp"))
Call TombolEdit()
MsgBox("Data Ini Sudah Tersimpan Pada Tabel Nasabah !")
Else
xkode = Kode.Text
Call HapusForm()
Kode.Text = xkode
Call TombolSimpan()
End If
DR.Close()
Nama.Focus()
End If
End Sub
End Class
Hasil Program penerapan kriptografi pada record database menggunakan program VB NET.
Screen Pertama
Sewaktu data disearching maka record asli masih nampak, tanpa dilakukan Dekripsi
Screen Kedua
Setelah di Dekripsikan maka akan terlihat record aslinya.
Setelah di Dekripsikan maka akan terlihat record aslinya.
Adapun fungsi untuk melakukan Enkripsi dan Dekripsi dapat dilihat berikut ini :
Saat melakukan Enkripsi
Function ENCCaesar(ByVal Plain As String) As String
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Plain)
x = Mid(Plain, i, i)
x = Chr(Asc(x) + 3)
xkalimat = xkalimat + x
Next
ENCCaesar = xkalimat
End Function
Lihat pemakaiannya disini.
SQL = "INSERT INTO Nasabah(Kode, Nama, Alamat, Telp)" & _
"Values (`" & Kode.Text & "`,`" & _
ENCCaesar(Nama.Text) & "`,`" & _
ENCCaesar(Alamat.Text) & "`,`" & _
ENCCaesar(Telp.Text) & "`)"
serta
SQL = "UPDATE Nasabah SET Nama=`" & ENCCaesar(Nama.Text) & "`, " & _
" Alamat=`" & ENCCaesar(Alamat.Text) & "`, " & _
" Telp=`" & ENCCaesar(Telp.Text) & "` " & _
" Where Kode=`" & Kode.Text & "`"
Saat melakukan Dekripsi
Function DECCaesar(ByVal Chiper As String) As String
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Chiper)
x = Mid(Chiper, i, i)
x = Chr(Asc(x) - 3)
xkalimat = xkalimat + x
Next
DECCaesar = xkalimat
End Function
dan lihat pemakaiannya disini.
Nama.Text = DECCaesar(DR("Nama"))
Alamat.Text = DECCaesar(DR("Alamat"))
Telp.Text = DECCaesar(DR("Telp"))
Saat melakukan Enkripsi
Function ENCCaesar(ByVal Plain As String) As String
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Plain)
x = Mid(Plain, i, i)
x = Chr(Asc(x) + 3)
xkalimat = xkalimat + x
Next
ENCCaesar = xkalimat
End Function
Lihat pemakaiannya disini.
SQL = "INSERT INTO Nasabah(Kode, Nama, Alamat, Telp)" & _
"Values (`" & Kode.Text & "`,`" & _
ENCCaesar(Nama.Text) & "`,`" & _
ENCCaesar(Alamat.Text) & "`,`" & _
ENCCaesar(Telp.Text) & "`)"
serta
SQL = "UPDATE Nasabah SET Nama=`" & ENCCaesar(Nama.Text) & "`, " & _
" Alamat=`" & ENCCaesar(Alamat.Text) & "`, " & _
" Telp=`" & ENCCaesar(Telp.Text) & "` " & _
" Where Kode=`" & Kode.Text & "`"
Saat melakukan Dekripsi
Function DECCaesar(ByVal Chiper As String) As String
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Chiper)
x = Mid(Chiper, i, i)
x = Chr(Asc(x) - 3)
xkalimat = xkalimat + x
Next
DECCaesar = xkalimat
End Function
dan lihat pemakaiannya disini.
Nama.Text = DECCaesar(DR("Nama"))
Alamat.Text = DECCaesar(DR("Alamat"))
Telp.Text = DECCaesar(DR("Telp"))
Sumber : Mesran.net