oke ini terinspirasi dari Tugas Kuliah baru-baru ini.
so mari mengenal MD5
Dalam kriptografi, MD5 (Message-Digest algortihm 5) ialah fungsi hash kriptografik yang digunakan secara luas dengan hash value 128-bit. Pada standart Internet (RFC 1321), MD5 telah dimanfaatkan secara bermacam-macam pada aplikasi keamanan, dan MD5 juga umum digunakan untuk melakukan pengujian integritas sebuah file.
MD5 di desain oleh Ronald Rivest pada tahun 1991 untuk menggantikan hash function sebelumnya, MD4. Pada tahun 1996, sebuah kecacatan ditemukan dalam desainnya, walau bukan kelemahan fatal, pengguna kriptografi mulai menganjurkan menggunakan algoritma lain, seperti SHA-1 (klaim terbaru menyatakan bahwa SHA-1 juga cacat). Pada tahun 2004, kecacatan-kecacatan yang lebih serius ditemukan menyebabkan penggunaan algoritma tersebut dalam tujuan untuk keamanan jadi makin dipertanyakan.
oke cukup pengetahuan singkatnya mengenai MD5.
sekarang buatlah form seperti dibawah ini atau ya terserah lah yang penting ada tools
jangan lupa menabahkan "References" "System.Security" ".NET"
Menu-Project-Add Reference-TAB .NET-System.Security
nah sekarang tulislah koding seperti dibawah ini
Imports System.Security.Cryptography
Public Class ENKRIPSI_DESKRIPSI
Dim FuncCls As New CommonFunctionsCls()
Public Class EncryptDecryptClass
Private Shared m_strPassPhrase As String = "MyPriv@Password!$$"
Private Shared m_strHashAlgorithm As String = "MD5"
Private Shared m_strPasswordIterations As Integer = 2
Private Shared m_strInitVector As String = "@1B2c3D4e5F6g7H8"
Private Shared m_intKeySize As Integer = 256
'Encrypt Function:
Friend Shared Function EncryptPasswordMD5(ByVal plainText As String, ByVal p_strSaltValue As String) As String
Dim strReturn As String = String.Empty
Try
Dim initVectorBytes As Byte()
initVectorBytes = System.Text.Encoding.ASCII.GetBytes(m_strInitVector)
Dim saltValueBytes As Byte()
saltValueBytes = System.Text.Encoding.ASCII.GetBytes(p_strSaltValue)
Dim plainTextBytes As Byte()
plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText)
Dim password As Rfc2898DeriveBytes
password = New Rfc2898DeriveBytes(m_strPassPhrase, _
saltValueBytes, _
m_strPasswordIterations)
Dim keyBytes As Byte()
Dim intKeySize As Integer = 0
intKeySize = CType((m_intKeySize / 8), Integer)
keyBytes = password.GetBytes(intKeySize)
Dim symmetricKey As System.Security.Cryptography.RijndaelManaged
symmetricKey = New System.Security.Cryptography.RijndaelManaged
symmetricKey.Mode = System.Security.Cryptography.CipherMode.CBC
Dim encryptor As System.Security.Cryptography.ICryptoTransform
encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes)
Dim memoryStream As System.IO.MemoryStream
memoryStream = New System.IO.MemoryStream
Dim cryptoStream As System.Security.Cryptography.CryptoStream
cryptoStream = New System.Security.Cryptography.CryptoStream(memoryStream, _
encryptor, _
System.Security.Cryptography.CryptoStreamMode.Write)
' Start encrypting.
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)
' Finish encrypting.
cryptoStream.FlushFinalBlock()
' Convert our encrypted data from a memory stream into a byte array.
Dim cipherTextBytes As Byte()
cipherTextBytes = memoryStream.ToArray()
' Close both streams.
memoryStream.Close()
cryptoStream.Close()
' Convert encrypted data into a base64-encoded string.
Dim cipherText As String
cipherText = Convert.ToBase64String(cipherTextBytes)
' Return encrypted string.
strReturn = cipherText
Catch ex As Exception
strReturn = Nothing
End Try
Return strReturn
End Function
'Decrypt Function:
Friend Shared Function DecryptPasswordMD5(ByVal cipherText As String, ByVal p_strSaltValue As String) As String
Dim strReturn As String = String.Empty
Try
Dim initVectorBytes As Byte()
initVectorBytes = System.Text.Encoding.ASCII.GetBytes(m_strInitVector)
Dim saltValueBytes As Byte()
saltValueBytes = System.Text.Encoding.ASCII.GetBytes(p_strSaltValue)
Dim cipherTextBytes As Byte()
cipherTextBytes = Convert.FromBase64String(cipherText)
Dim password As Rfc2898DeriveBytes
password = New Rfc2898DeriveBytes(m_strPassPhrase, _
saltValueBytes, _
m_strPasswordIterations)
Dim keyBytes As Byte()
Dim intKeySize As Integer
intKeySize = CType((m_intKeySize / 8), Integer)
keyBytes = password.GetBytes(intKeySize)
Dim symmetricKey As System.Security.Cryptography.RijndaelManaged
symmetricKey = New System.Security.Cryptography.RijndaelManaged
symmetricKey.Mode = System.Security.Cryptography.CipherMode.CBC
Dim decryptor As System.Security.Cryptography.ICryptoTransform
decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)
Dim memoryStream As System.IO.MemoryStream
memoryStream = New System.IO.MemoryStream(cipherTextBytes)
Dim cryptoStream As System.Security.Cryptography.CryptoStream
cryptoStream = New System.Security.Cryptography.CryptoStream(memoryStream, _
decryptor, _
System.Security.Cryptography.CryptoStreamMode.Read)
Dim plainTextBytes As Byte()
ReDim plainTextBytes(cipherTextBytes.Length)
' Start decrypting.
Dim decryptedByteCount As Integer
decryptedByteCount = cryptoStream.Read(plainTextBytes, _
0, _
plainTextBytes.Length)
' Close both streams.
memoryStream.Close()
cryptoStream.Close()
Dim plainText As String
plainText = System.Text.Encoding.UTF8.GetString(plainTextBytes, _
0, _
decryptedByteCount)
' Return decrypted string.
strReturn = plainText
Catch ex As Exception
strReturn = Nothing
End Try
Return strReturn
End Function
End Class
Public Class CommonFunctionsCls
Public Function EncryptPassword(ByVal Password As String) As String
'Encrypt the Password
Dim sEncryptedPassword As String = ""
Dim sEncryptKey As String = "P@SSW@RD@09" 'Should be minimum 8 characters
Try
sEncryptedPassword = EncryptDecryptClass.EncryptPasswordMD5(Password, sEncryptKey)
Catch ex As Exception
Return sEncryptedPassword
End Try
Return sEncryptedPassword
End Function
Public Function DecryptPassword(ByVal Password As String) As String
'Encrypt the Password
Dim sDecryptedPassword As String = ""
Dim sEncryptKey As String = "P@SSW@RD@09" 'Should be minimum 8 characters
Try
sDecryptedPassword = EncryptDecryptClass.DecryptPasswordMD5(Password, sEncryptKey)
Catch ex As Exception
Return sDecryptedPassword
End Try
Return sDecryptedPassword
End Function
End Class
Private Sub BtnENKRIPSI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnENKRIPSI.Click
TxtENKRIP.Text = FuncCls.EncryptPassword(TxtPASSWORD.Text.Trim)
End Sub
Private Sub BtnDEKRIPSI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDEKRIPSI.Click
TxtDEKRIP.Text = FuncCls.DecryptPassword(TxtENKRIP.Text.Trim)
End Sub
Private Sub BtnCLEAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCLEAR.Click
TxtPASSWORD.Text = ""
TxtENKRIP.Text = ""
TxtDEKRIP.Text = ""
TxtENKRIP.Focus()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
End Class
run aplikasinya maka akan running seperti dibawah, isilah teks Password dan klik buttonnya untuk mengetahui hasil tersebut
dasar sesat, itu bukan hash MD5 -_-
ReplyDeletepesan
ReplyDelete