[TUT]Basic Encrypter\Decrypter

Posts 16–30 of 31 · Page 2 of 3
The Only Problem with your code is you forgot to specify an IV for the encryption algo.
I just through this together you can use it if you want. I have to Add Encryption and Decryption for Files using crypto streams and such.
Code:
Imports System.Security.Cryptography
Module Encryption
    Public Function AESEncrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim AES As AesCryptoServiceProvider
        With AES
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim AESEncryptor As ICryptoTransform = AES.CreateEncryptor
        Dim DataBuffer As Byte()
        Dim EncryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        EncryptedData = AESEncryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return EncryptedData
    End Function

    Public Function AESDecrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim AES As AesCryptoServiceProvider
        With AES
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim AESDecryptor As ICryptoTransform = AES.CreateDecryptor
        Dim DataBuffer As Byte()
        Dim DecryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        DecryptedData = AESDecryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return DecryptedData
    End Function

    Public Function RC2Encrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim RC2 As RC2CryptoServiceProvider
        With RC2
            .Mode = CipherMode.ECB
            .UseSalt = True
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim RC2Encryptor As ICryptoTransform = RC2.CreateEncryptor
        Dim DataBuffer As Byte()
        Dim EncryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        EncryptedData = RC2Encryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return EncryptedData
    End Function

    Public Function RC2Decrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim RC2 As RC2CryptoServiceProvider
        With RC2
            .Mode = CipherMode.ECB
            .UseSalt = True
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim RC2Decryptor As ICryptoTransform = RC2.CreateDecryptor
        Dim DataBuffer As Byte()
        Dim DecryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        DecryptedData = RC2Decryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return DecryptedData
    End Function

    Public Function DESEncrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim DES As DESCryptoServiceProvider
        With DES
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim DESEncryptor As ICryptoTransform = DES.CreateEncryptor
        Dim DataBuffer As Byte()
        Dim EncryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        EncryptedData = DESEncryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return EncryptedData
    End Function

    Public Function DESDecrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim DES As DESCryptoServiceProvider
        With DES
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim DESDecryptor As ICryptoTransform = DES.CreateDecryptor
        Dim Databuffer As Byte()
        Dim DecryptedData As Byte()
        Databuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        DecryptedData = DESDecryptor.TransformFinalBlock(Databuffer, 0, Databuffer.Length)
        Return DecryptedData
    End Function

    Public Function TripleDESEncrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim TripleDes As TripleDESCryptoServiceProvider
        With TripleDes
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim TripleDESEncryptor As ICryptoTransform = TripleDes.CreateEncryptor
        Dim Databuffer As Byte()
        Dim EncryptedData As Byte()
        Databuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        EncryptedData = TripleDESEncryptor.TransformFinalBlock(Databuffer, 0, Databuffer.Length)
        Return EncryptedData
    End Function

    Public Function TripleDESDecrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim TripleDes As TripleDESCryptoServiceProvider
        With TripleDes
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim TripleDESDecryptor As ICryptoTransform = TripleDes.CreateDecryptor
        Dim DataBuffer As Byte()
        Dim DecryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        DecryptedData = TripleDESDecryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return DecryptedData
    End Function

    
    Public Function ToBase64String(ByVal Bytes As Byte()) As String
        Return Convert.ToBase64String(Bytes)
    End Function
End Module
The Only Problem with your code is you forgot to specify an IV for the encryption algo.
I just through this together you can use it if you want. I have to Add Encryption and Decryption for Files using crypto streams and such.
Code:
Imports System.Security.Cryptography
Module Encryption
    Public Function AESEncrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim AES As AesCryptoServiceProvider
        With AES
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim AESEncryptor As ICryptoTransform = AES.CreateEncryptor
        Dim DataBuffer As Byte()
        Dim EncryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        EncryptedData = AESEncryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return EncryptedData
    End Function

    Public Function AESDecrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim AES As AesCryptoServiceProvider
        With AES
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim AESDecryptor As ICryptoTransform = AES.CreateDecryptor
        Dim DataBuffer As Byte()
        Dim DecryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        DecryptedData = AESDecryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return DecryptedData
    End Function

    Public Function RC2Encrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim RC2 As RC2CryptoServiceProvider
        With RC2
            .Mode = CipherMode.ECB
            .UseSalt = True
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim RC2Encryptor As ICryptoTransform = RC2.CreateEncryptor
        Dim DataBuffer As Byte()
        Dim EncryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        EncryptedData = RC2Encryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return EncryptedData
    End Function

    Public Function RC2Decrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim RC2 As RC2CryptoServiceProvider
        With RC2
            .Mode = CipherMode.ECB
            .UseSalt = True
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim RC2Decryptor As ICryptoTransform = RC2.CreateDecryptor
        Dim DataBuffer As Byte()
        Dim DecryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        DecryptedData = RC2Decryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return DecryptedData
    End Function

    Public Function DESEncrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim DES As DESCryptoServiceProvider
        With DES
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim DESEncryptor As ICryptoTransform = DES.CreateEncryptor
        Dim DataBuffer As Byte()
        Dim EncryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        EncryptedData = DESEncryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return EncryptedData
    End Function

    Public Function DESDecrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim DES As DESCryptoServiceProvider
        With DES
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim DESDecryptor As ICryptoTransform = DES.CreateDecryptor
        Dim Databuffer As Byte()
        Dim DecryptedData As Byte()
        Databuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        DecryptedData = DESDecryptor.TransformFinalBlock(Databuffer, 0, Databuffer.Length)
        Return DecryptedData
    End Function

    Public Function TripleDESEncrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim TripleDes As TripleDESCryptoServiceProvider
        With TripleDes
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim TripleDESEncryptor As ICryptoTransform = TripleDes.CreateEncryptor
        Dim Databuffer As Byte()
        Dim EncryptedData As Byte()
        Databuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        EncryptedData = TripleDESEncryptor.TransformFinalBlock(Databuffer, 0, Databuffer.Length)
        Return EncryptedData
    End Function

    Public Function TripleDESDecrypt(ByVal Key As String, ByVal Data As String) As Byte()
        On Error Resume Next
        Dim TripleDes As TripleDESCryptoServiceProvider
        With TripleDes
            .Mode = CipherMode.ECB
            .Key = System.Text.ASCIIEncoding.ASCII.GetBytes(Key)
            .IV = .Key
        End With
        Dim TripleDESDecryptor As ICryptoTransform = TripleDes.CreateDecryptor
        Dim DataBuffer As Byte()
        Dim DecryptedData As Byte()
        DataBuffer = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
        DecryptedData = TripleDESDecryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
        Return DecryptedData
    End Function

    
    Public Function ToBase64String(ByVal Bytes As Byte()) As String
        Return Convert.ToBase64String(Bytes)
    End Function
End Module
Yah but thats a complex code to a beginner, i just wanted to make a simple one for the beginner, i doubt a beginner would understand that code
Bombs doesn't copy and paste, I know that as a fact. He makes combat arms multitools and doesn't afraid of anything.
I taught bombs everything he knows. :/ Lol. Where ya been man? Haven't seen you on MSN.
Quote Originally Posted by Calebb View Post
I taught bombs everything he knows. :/ Lol. Where ya been man? Haven't seen you on MSN.
i just got back from vacation, i was on msn all day yesterday tho
Quote Originally Posted by mnpeep View Post
awesome TUT. congrats ur on my respected list.
thanks bro
awesome TUT. congrats ur on my respected list.
Quote Originally Posted by bombsaway707
thanks bro
ya welcome, also i changed my sig so you can see it now.
Quote Originally Posted by mnpeep View Post
ya welcome, also i changed my sig so you can see it now.
haha nice, your the first person to put me in their respect list
Quote Originally Posted by Zoom View Post
Yeah almost
Hejsan's jealous
Great Encrpyter dude i just sent it to like six kids . It is great.
Quote Originally Posted by RawVb View Post
Great Encrpyter dude i just sent it to like six kids . It is great.
thanks man
Quote Originally Posted by deathninjak0 View Post
Whats a Encrypter?
............................................______ __
....................................,.-‘”...................``~.,
.............................,.-”...................................“-.,
.........................,/...............................................”:,
.....................,?........................... ...........................\,
.................../.................................................. .........,}
................./.................................................. ....,:`^`..}
.............../.................................................. .,:”........./
..............?.....__............................ .............:`.........../
............./__.(.....“~-,_..............................,:`........../
.........../(_....”~,_........“~,_....................,:`..... ..._/
..........{.._$;_......”=,_.......“-,_.......,.-~-,},.~”;/....}
...........((.....*~_.......”=-._......“;,,./`..../”............../
...,,,___.\`~,......“~.,....................`..... }............../
............(....`=-,,.......`........................(......;_,,-”
............/.`~,......`-...............................\....../\
.............\`~.*-,.....................................|,./.....\,__
,,_..........}.>-._\...................................|........... ...`=~-,
.....`=~-,_\_......`\,.................................\
...................`=~-,,.\,...............................\
................................`:,,.............. .............`\..............__
.....................................`=-,...................,%`>--==``
........................................_\........ ..._,-%.......`\
...................................,<`.._|_,-&``................`\
Quote Originally Posted by Lolland View Post
............................................______ __
....................................,.-‘”...................``~.,
.............................,.-”...................................“-.,
.........................,/...............................................”:,
.....................,?........................... ...........................\,
.................../.................................................. .........,}
................./.................................................. ....,:`^`..}
.............../.................................................. .,:”........./
..............?.....__............................ .............:`.........../
............./__.(.....“~-,_..............................,:`........../
.........../(_....”~,_........“~,_....................,:`..... ..._/
..........{.._$;_......”=,_.......“-,_.......,.-~-,},.~”;/....}
...........((.....*~_.......”=-._......“;,,./`..../”............../
...,,,___.\`~,......“~.,....................`..... }............../
............(....`=-,,.......`........................(......;_,,-”
............/.`~,......`-...............................\....../\
.............\`~.*-,.....................................|,./.....\,__
,,_..........}.>-._\...................................|........... ...`=~-,
.....`=~-,_\_......`\,.................................\
...................`=~-,,.\,...............................\
................................`:,,.............. .............`\..............__
.....................................`=-,...................,%`>--==``
........................................_\........ ..._,-%.......`\
...................................,<`.._|_,-&``................`\
Shutup
Posts 16–30 of 31 · Page 2 of 3
This thread is closed for replies.

Similar Threads

Tags for this Thread

Talk with us