Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    o0OpurezO0o's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    behind you.
    Posts
    354
    Reputation
    10
    Thanks
    26
    My Mood
    Sick

    Encrypt/Decrypt vb.Net?

    Is there a source for a Encrypter/Decrypter (needs password to access)? Cause i need it for my laptop.

  2. The Following User Says Thank You to o0OpurezO0o For This Useful Post:

    vitu8 (11-20-2010)

  3. #2
    wtfiwantthatname's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Posts
    260
    Reputation
    10
    Thanks
    39
    My Mood
    Bored
    heres code for encryption. Theres a function for strings and bytes for each encryption type.

    Code:
    Imports System.Security.Cryptography
    Module Encryption
        Public Function AESEncrypt(ByVal Key As String, ByVal Data As String) As String
            Try
                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 ByteToString(EncryptedData)
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
    
        Public Function AESEncrypt(ByVal Key() As Byte, ByVal Data() As Byte) As Byte()
            Try
                Dim AES As AesCryptoServiceProvider
                With AES
                    .Mode = CipherMode.ECB
                    .Key = Key
                    .IV = .Key
                End With
                Dim AESEncryptor As ICryptoTransform = AES.CreateEncryptor
                Dim DataBuffer As Byte()
                Dim EncryptedData As Byte()
                DataBuffer = Data
                EncryptedData = AESEncryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
                Return EncryptedData
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
    
        Public Function AESDecrypt(ByVal Key() As Byte, ByVal Data() As Byte) As Byte()
            Try
                Dim AES As AesCryptoServiceProvider
                With AES
                    .Mode = CipherMode.ECB
                    .Key = Key
                    .IV = .Key
                End With
                Dim AESDecryptor As ICryptoTransform = AES.CreateDecryptor
                Dim DataBuffer As Byte()
                Dim DecryptedData As Byte()
                DataBuffer = Data
                DecryptedData = AESDecryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
                Return DecryptedData
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
    
        Public Function AESDecrypt(ByVal Key As String, ByVal Data As String) As String
            Try
                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 ByteToString(DecryptedData)
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
    
        Public Function RC2Encrypt(ByVal Key As String, ByVal Data As String) As Byte()
            Try
                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
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
        Public Function RC2Encrypt(ByVal Key() As Byte, ByVal Data() As Byte) As Byte()
            Try
                Dim RC2 As RC2CryptoServiceProvider
                With RC2
                    .Mode = CipherMode.ECB
                    .UseSalt = True
                    .Key = Key
                    .IV = .Key
                End With
                Dim RC2Encryptor As ICryptoTransform = RC2.CreateEncryptor
                Dim databuffer As Byte()
                Dim EncryptedData As Byte()
                databuffer = Data
                EncryptedData = RC2Encryptor.TransformFinalBlock(databuffer, 0, databuffer.Length)
                Return EncryptedData
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
        Public Function RC2Decrypt(ByVal key() As Byte, ByVal data() As Byte) As Byte()
            Try
                Dim RC2 As RC2CryptoServiceProvider
                With RC2
                    .Mode = CipherMode.ECB
                    .UseSalt = True
                    .Key = key
                    .IV = .Key
                End With
                Dim RC2Decryptor As ICryptoTransform = RC2.CreateDecryptor
                Dim databuffer As Byte()
                Dim Decrypteddata As Byte()
                databuffer = data
                Decrypteddata = RC2Decryptor.TransformFinalBlock(databuffer, 0, databuffer.Length)
                Return Decrypteddata
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
        Public Function RC2Decrypt(ByVal Key As String, ByVal Data As String) As String
            Try
                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 ByteToString(DecryptedData)
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
        Public Function DESEncrypt(ByVal Key As String, ByVal Data As String) As String
            Try
                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 ByteToString(EncryptedData)
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
        Public Function DESEncrypt(ByVal key() As Byte, ByVal data() As Byte) As Byte()
            Try
                Dim DES As DESCryptoServiceProvider
                With DES
                    .Mode = CipherMode.ECB
                    .Key = key
                    .IV = .Key
                End With
                Dim DESEncryptor As ICryptoTransform = DES.CreateEncryptor
                Dim DataBuffer As Byte()
                Dim Encrypteddata As Byte()
                DataBuffer = data
                Encrypteddata = DESEncryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
                Return Encrypteddata
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
    
    
        Public Function DESDecrypt(ByVal Key As String, ByVal Data As String) As String
            Try
                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 ByteToString(DecryptedData)
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
        Public Function DESDecrypt(ByVal Key() As Byte, ByVal data() As Byte) As Byte()
            Try
                Dim DES As DESCryptoServiceProvider
                With DES
                    .Mode = CipherMode.ECB
                    .Key = Key
                    .IV = .Key
                End With
                Dim DESDecryptor As ICryptoTransform = DES.CreateDecryptor
                Dim DataBuffer As Byte()
                Dim DecryptedData As Byte()
                DataBuffer = data
                DecryptedData = DESDecryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
                Return DecryptedData
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
        Public Function TripleDESEncrypt(ByVal Key As String, ByVal Data As String) As String
            Try
                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 ByteToString(EncryptedData)
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
        Public Function TripleDESEncrypt(ByVal key As Byte(), ByVal data As Byte()) As Byte()
            Try
                Dim TripleDes As TripleDESCryptoServiceProvider
                With TripleDes
                    .Mode = CipherMode.ECB
                    .Key = key
                    .IV = .Key
                End With
                Dim TripleDESEncryptor As ICryptoTransform = TripleDes.CreateEncryptor
                Dim DataBuffer As Byte()
                Dim EncryptedData As Byte()
                DataBuffer = data
                EncryptedData = TripleDESEncryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
                Return EncryptedData
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
    
        Public Function TriplesDESDecrypt(ByVal key As Byte(), ByVal Data As Byte()) As Byte()
            Try
                Dim TripleDes As TripleDESCryptoServiceProvider
                With TripleDes
                    .Mode = CipherMode.ECB
                    .Key = key
                    .IV = .Key
                End With
                Dim TripleDESDecryptor As ICryptoTransform = TripleDes.CreateDecryptor
                Dim DataBuffer As Byte()
                Dim DecryptedData As Byte()
                DataBuffer = Data
                DecryptedData = TripleDESDecryptor.TransformFinalBlock(DataBuffer, 0, DataBuffer.Length)
                Return DecryptedData
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
        Public Function TripleDESDecrypt(ByVal Key As String, ByVal Data As String) As String
            Try
                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 ByteToString(DecryptedData)
            Catch ex As Exception
                MessageBox.Show("The Following Error(s) occured: " & ex.Message, "Error", MessageBoxButtons.OK)
            End Try
        End Function
    
    
        Public Function ByteToString(ByVal Bytes As Byte()) As String
            Return Convert.ToString(Bytes)
        End Function
    End Module
    "I don't believe in an afterlife, so I don't have to spend my whole life fearing hell, or fearing heaven even more. For whatever the tortures of hell, I think the boredom of heaven would be even worse." - Isaac Asimov

  4. #3
    o0OpurezO0o's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    behind you.
    Posts
    354
    Reputation
    10
    Thanks
    26
    My Mood
    Sick
    What? I didnt understand what that is.

    And what is the button codec to encrypt?

    Edit: I get 32 Warnings:

    Code:
    Warning	1	Variable 'AES' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	6	18	WindowsApplication1
    Warning	2	Function 'AESEncrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	20	5	WindowsApplication1
    Warning	3	Variable 'AES' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	26	18	WindowsApplication1
    Warning	4	Function 'AESEncrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	40	5	WindowsApplication1
    Warning	5	Variable 'AES' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	46	18	WindowsApplication1
    Warning	6	Function 'AESDecrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	60	5	WindowsApplication1
    Warning	7	Variable 'AES' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	66	18	WindowsApplication1
    Warning	8	Function 'AESDecrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	80	5	WindowsApplication1
    Warning	9	Variable 'RC2' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	86	18	WindowsApplication1
    Warning	10	Function 'RC2Encrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	101	5	WindowsApplication1
    Warning	11	Variable 'RC2' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	106	18	WindowsApplication1
    Warning	12	Function 'RC2Encrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	121	5	WindowsApplication1
    Warning	13	Variable 'RC2' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	126	18	WindowsApplication1
    Warning	14	Function 'RC2Decrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	141	5	WindowsApplication1
    Warning	15	Variable 'RC2' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	146	18	WindowsApplication1
    Warning	16	Function 'RC2Decrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	161	5	WindowsApplication1
    Warning	17	Variable 'DES' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	166	18	WindowsApplication1
    Warning	18	Function 'DESEncrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	180	5	WindowsApplication1
    Warning	19	Variable 'DES' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	185	18	WindowsApplication1
    Warning	20	Function 'DESEncrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	199	5	WindowsApplication1
    Warning	21	Variable 'DES' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	206	18	WindowsApplication1
    Warning	22	Function 'DESDecrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	220	5	WindowsApplication1
    Warning	23	Variable 'DES' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	225	18	WindowsApplication1
    Warning	24	Function 'DESDecrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	239	5	WindowsApplication1
    Warning	25	Variable 'TripleDes' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	244	18	WindowsApplication1
    Warning	26	Function 'TripleDESEncrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	258	5	WindowsApplication1
    Warning	27	Variable 'TripleDes' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	263	18	WindowsApplication1
    Warning	28	Function 'TripleDESEncrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	277	5	WindowsApplication1
    Warning	29	Variable 'TripleDes' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	283	18	WindowsApplication1
    Warning	30	Function 'TriplesDESDecrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	297	5	WindowsApplication1
    Warning	31	Variable 'TripleDes' is used before it has been assigned a value. A null reference exception could result at runtime.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	302	18	WindowsApplication1
    Warning	32	Function 'TripleDESDecrypt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Encryption.vb	316	5	WindowsApplication1
    Last edited by o0OpurezO0o; 11-20-2010 at 05:06 PM.

  5. #4
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Even though I am anti ignoring warnings. I wrote a whole article on it, those warnings can be ignored. The application will still build with warnings, and will still work.

    What WTF neglected to mention is the code he is providing is a rendition of a old module with some minor declaration changes (Microsoft standard btw) in either case, it simply means that each of those functions can return null, but I wouldn't worry about it.

    In general, This may help you out.

    https://support.microsof*****m/kb/301070

    Same source (again with original declarations), just with explanations.

    Full source, From MSDN

    Code:
    Imports System
    Imports System.IO
    Imports System.Security
    Imports System.Security.Cryptography
    Imports System****ntime.InteropServices
    Imports System.Text
    
    
    Module Module1
    
       ' Call this function to remove the key from memory after it is used for security.
       <DllImport("kernel32.dll")> _
       Public Sub ZeroMemory(ByVal addr As IntPtr, ByVal size As Integer)
       End Sub
    
       ' Function to generate a 64-bit key.
       Function GenerateKey() As String
          ' Create an instance of a symmetric algorithm. The key and the IV are generated automatically.
          Dim desCrypto As DESCryptoServiceProvider = DESCryptoServiceProvider.Create()
    
          ' Use the automatically generated key for encryption. 
          Return ASCIIEncoding.ASCII.GetString(desCrypto.Key)
    
       End Function
    
       Sub EncryptFile(ByVal sInputFilename As String, _
                      ByVal sOutputFilename As String, _
                      ByVal sKey As String)
    
          Dim fsInput As New FileStream(sInputFilename, _
                                      FileMode.Open, FileAccess.Read)
          Dim fsEncrypted As New FileStream(sOutputFilename, _
                                      FileMode.Create, FileAccess.Write)
    
          Dim DES As New DESCryptoServiceProvider()
    
          'Set secret key for DES algorithm.
          'A 64-bit key and an IV are required for this provider.
          DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey)
    
          'Set the initialization vector.
          DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)
    
          'Create the DES encryptor from this instance.
          Dim desencrypt As ICryptoTransform = DES.CreateEncryptor()
          'Create the crypto stream that transforms the file stream by using DES encryption.
          Dim cryptostream As New CryptoStream(fsEncrypted, _
                                              desencrypt, _
                                              CryptoStreamMode.Write)
    
          'Read the file text to the byte array.
          Dim bytearrayinput(fsInput.Length - 1) As Byte
          fsInput.Read(bytearrayinput, 0, bytearrayinput.Length)
          'Write out the DES encrypted file.
          cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length)
          cryptostream.Close()
       End Sub
    
       Sub DecryptFile(ByVal sInputFilename As String, _
           ByVal sOutputFilename As String, _
           ByVal sKey As String)
    
          Dim DES As New DESCryptoServiceProvider()
          'A 64-bit key and an IV are required for this provider.
          'Set the secret key for the DES algorithm.
          DES.Key() = ASCIIEncoding.ASCII.GetBytes(sKey)
          'Set the initialization vector.
          DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey)
    
          'Create the file stream to read the encrypted file back.
          Dim fsread As New FileStream(sInputFilename, FileMode.Open, FileAccess.Read)
          'Create the DES decryptor from the DES instance.
          Dim desdecrypt As ICryptoTransform = DES.CreateDecryptor()
          'Create the crypto stream set to read and to do a DES decryption transform on incoming bytes.
          Dim cryptostreamDecr As New CryptoStream(fsread, desdecrypt, CryptoStreamMode.Read)
          'Print out the contents of the decrypted file.
          Dim fsDecrypted As New StreamWriter(sOutputFilename)
          fsDecrypted.Write(New StreamReader(cryptostreamDecr).ReadToEnd)
          fsDecrypted.Flush()
          fsDecrypted.Close()
       End Sub
    
       Public Sub Main()
          'Must be 64 bits, 8 bytes.
          Dim sSecretKey As String
    
          ' Get the key for the file to encrypt.
          ' You can distribute this key to the user who will decrypt the file.
          sSecretKey = GenerateKey()
    
          ' For additional security, pin the key.
          Dim gch As GCHandle = GCHandle.Alloc(sSecretKey, GCHandleType.Pinned)
    
    
          ' Encrypt the file.        
          EncryptFile("%USERPROFILE%\MyData.txt", _
                          "%USERPROFILE%\Encrypted.txt", _
                          sSecretKey)
    
          ' Decrypt the file.
          DecryptFile("%USERPROFILE%\Encrypted.txt", _
                      "%USERPROFILE%\Decrypted.txt", _
                      sSecretKey)
    
          ' Remove the key from memory. 
          ZeroMemory(gch.AddrOfPinnedObject(), sSecretKey.Length * 2)
          gch.Free()
       End Sub
    
    End Module
    Last edited by NextGen1; 11-20-2010 at 05:33 PM.


     


     


     



    The Most complete application MPGH will ever offer - 68%




  6. The Following User Says Thank You to NextGen1 For This Useful Post:

    o0OpurezO0o (11-20-2010)

  7. #5
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    It's a warning, who cares?

  8. The Following User Says Thank You to freedompeace For This Useful Post:

    [MPGH]master131 (11-20-2010)

  9. #6
    o0OpurezO0o's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    behind you.
    Posts
    354
    Reputation
    10
    Thanks
    26
    My Mood
    Sick
    OK, so the two Codes:

    Code:
            ' Encrypt the file.        
            EncryptFile("%USERPROFILE%\MyData.txt", _
                            "%USERPROFILE%\Encrypted.txt", _
                            sSecretKey)
    
            ' Decrypt the file.
            DecryptFile("%USERPROFILE%\Encrypted.txt", _
                        "%USERPROFILE%\Decrypted.txt", _
                        sSecretKey)
    i put in the two buttons i want to Encrypt/Decrypt?

    BTW thanks NextGen.


    anyone? answer please
    Last edited by Lolland; 11-21-2010 at 09:17 PM.

  10. #7
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Quote Originally Posted by o0OpurezO0o View Post
    anyone? answer please
    This

    Code:
     EncryptFile("%USERPROFILE%\MyData.txt", _
                          "%USERPROFILE%\Encrypted.txt", _
                          sSecretKey)
    
          ' Decrypt the file.
          DecryptFile("%USERPROFILE%\Encrypted.txt", _
                      "%USERPROFILE%\Decrypted.txt", _
                      sSecretKey)
    Is a sample, You will need to add one button

    Encrypt

    and another

    Decrypt

    Then use the functions

    Code:
    EncryptFile(ByVal sInputFilename As String, _
                      ByVal sOutputFilename As String, _
                      ByVal sKey As String)
    In a example would be

    Code:
    EncryptFile("C:\test.txt","C:\TestEncrypted.txt, sSecretKey)
    This will encrypt the file test.txt and create a new encrypted file (from the original) called TestEncrypted.txt.

    Do the same to decrypt.

    Make sense?


     


     


     



    The Most complete application MPGH will ever offer - 68%




  11. #8
    o0OpurezO0o's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    behind you.
    Posts
    354
    Reputation
    10
    Thanks
    26
    My Mood
    Sick
    ERRORS!
    Code:
    Error	1	Expression expected.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb	7	21	WindowsApplication1
    Error	2	Expression expected.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb	8	19	WindowsApplication1
    Error	3	Expression expected.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb	9	19	WindowsApplication1
    Error	4	Argument not specified for parameter 'sKey' of 'Public Sub EncryptFile(sInputFilename As String, sOutputFilename As String, sKey As String)'.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb	11	9	WindowsApplication1
    Error	5	String constants must end with a double quote.	C:\Users\Owner\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb	11	35	WindowsApplication1

  12. #9
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,679
    My Mood
    Mellow
    All pretty self explanatory errors. You forgot a double quote at the end of a string, forgot to pass the third parameter into the Encryption function and whatever the first ones were.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  13. #10
    Lolland's Avatar
    Join Date
    Feb 2009
    Gender
    male
    Location
    Lolland!
    Posts
    3,156
    Reputation
    49
    Thanks
    868
    My Mood
    Inspired
    Please read over your errors before you post them /fp

  14. The Following User Says Thank You to Lolland For This Useful Post:

    [MPGH]master131 (11-21-2010)

  15. #11
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    Copy & Paste usually leads to several errors.



  16. The Following User Says Thank You to Blubb1337 For This Useful Post:

    Insane (11-22-2010)

  17. #12
    'Bruno's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Portugal
    Posts
    2,883
    Reputation
    290
    Thanks
    1,036
    My Mood
    Busy
    Quote Originally Posted by freedompeace View Post
    It's a warning, who cares?
    i really thought you were "awesome", but after this one... God...

    start coding in C, ignore your warning, then cry that your program randomly crash's or that you have some random stupid outputs.
    Light travels faster than sound. That's why most people seem bright until you hear them speak.

  18. The Following User Says Thank You to 'Bruno For This Useful Post:

    Lolland (11-22-2010)

  19. #13
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,679
    My Mood
    Mellow
    Quote Originally Posted by Brinuz View Post
    i really thought you were "awesome", but after this one... God...

    start coding in C, ignore your warning, then cry that your program randomly crash's or that you have some random stupid outputs.
    Agreed. Some warnings can be ignored (if you KNOW it won't affect your program (i.e you've taken error handling into account, or it's just an unused variable). Otherwise shit may hit the fan in a large way.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  20. #14
    o0OpurezO0o's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Location
    behind you.
    Posts
    354
    Reputation
    10
    Thanks
    26
    My Mood
    Sick
    I read them, i'm not a good error/warning reader.

    @NextGen1 Im still awaiting on that book you told me bout. Just notfy me about the progress.

  21. #15
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Quote Originally Posted by Brinuz View Post
    i really thought you were "awesome", but after this one... God...

    start coding in C, ignore your warning, then cry that your program randomly crash's or that you have some random stupid outputs.
    There are many warnings that you can ignore, and many that you cannot. In Visual Basic, they've pretty much made it so that every warning that should not be ignored is now an error, so it's easier for people to grasp the language.

    I do code in C, by the way. (Not much though, mainly C++)

Page 1 of 2 12 LastLast