File Encryption

kingheart

Member
Joined
Aug 30, 2009
Messages
11
Programming Experience
Beginner
i want to make a very simple project that will take a file as input and encrypt it and save the encrypted file.

how can i do this using visual basic?
user will put a 8-character( or more) length password only and will get the output without having too much headache.

what type encryption should be used?(Block cipher which?)

i was Linux user and new to windows and novice visual basic programmer .

please, your help appreciated .
just need the guide line.
Thanks Very Much.
 
VB.NET:
Public Class Crypto
    Private Shared DES As New TripleDESCryptoServiceProvider
    Private Shared MD5 As New MD5CryptoServiceProvider

    Public Shared Function MD5Hash(ByVal value As String) As Byte()
        Return MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(value))
    End Function

    Public Shared Function Encrypt(ByVal stringToEncrypt As String, ByVal key As String) As String
        DES.Key = MD5Hash(key)
        DES.Mode = CipherMode.ECB
        Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(stringToEncrypt)
        Return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
    End Function

    Public Shared Function Decrypt(ByVal encryptedString As String, ByVal key As String) As String
      Try  
        DES.Key = MD5Hash(key)
        DES.Mode = CipherMode.ECB
        Dim Buffer As Byte() = Convert.FromBase64String(encryptedString)
        Return ASCIIEncoding.ASCII.GetString(DES.CreateDecryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))
      Catch 
         MessageBox.Show("Wrong Key Number, decryption not available!")
      End Try 
    End Function

End Class

Call it:
VB.NET:
Crypto.Encrypt("yourString","yourKey")
:cool:
 
Last edited:
Back
Top