QuestionSolvedEncrypting Text

Posts 16–30 of 39 · Page 2 of 3
Quote Originally Posted by Cryptonic View Post


Not exactly what I was implying. My point is, you would need a method that you can easily understand, like my example above, so only the program can encrypt/decrypt the text. I'm even looking for a method like that.

Has anyone done this before?
What about MD5?

Here is a code I found via google. (Credit to: Adobler @ MSDN)
Code:
Imports System.Security.Cryptography

Imports System.Text

 

Public Class Form1

    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.CBC

        Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(stringToEncrypt)

        Return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))

        MsgBox("Done!")

    End Function

 

    Public Shared Function Decrypt(ByVal encryptedString As String, ByVal key As String) As String

        Try

            DES.Key = MD5Hash(key)

            DES.Mode = CipherMode.CBC

            Dim Buffer As Byte() = Convert.FromBase64String(encryptedString)

            Return ASCIIEncoding.ASCII.GetString(DES.CreateDecryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))

            MsgBox("Done!")

        Catch

            MsgBox("Wrong Key Number, decryption not available!")

        End Try

    End Function

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Decrypt(TextBox1.Text, TextBox2.Text)

    End Sub

 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        OpenFileDialog1.ShowDialog()

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Encrypt(TextBox1.Text, TextBox2.Text)

    End Sub

 

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

        TextBox1.Text = OpenFileDialog1.FileName

    End Sub

End Class
Quote Originally Posted by Jorndel View Post


What about MD5?

Here is a code I found via google. (Credit to: Adobler @ MSDN)
Code:
Imports System.Security.Cryptography

Imports System.Text

 

Public Class Form1

    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.CBC

        Dim Buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(stringToEncrypt)

        Return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))

        MsgBox("Done!")

    End Function

 

    Public Shared Function Decrypt(ByVal encryptedString As String, ByVal key As String) As String

        Try

            DES.Key = MD5Hash(key)

            DES.Mode = CipherMode.CBC

            Dim Buffer As Byte() = Convert.FromBase64String(encryptedString)

            Return ASCIIEncoding.ASCII.GetString(DES.CreateDecryptor().TransformFinalBlock(Buffer, 0, Buffer.Length))

            MsgBox("Done!")

        Catch

            MsgBox("Wrong Key Number, decryption not available!")

        End Try

    End Function

 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Decrypt(TextBox1.Text, TextBox2.Text)

    End Sub

 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        OpenFileDialog1.ShowDialog()

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Encrypt(TextBox1.Text, TextBox2.Text)

    End Sub

 

    Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk

        TextBox1.Text = OpenFileDialog1.FileName

    End Sub

End Class
Hmm.. When I try to encrypt, nothing happens. I even used a Try function, and no error came up. Since I can't encrypt, I can't decrypt...
Quote Originally Posted by Cryptonic View Post


Hmm.. When I try to encrypt, nothing happens. I even used a Try function, and no error came up. Since I can't encrypt, I can't decrypt...
Debug it? :\
Quote Originally Posted by 'Bruno View Post


Debug it? :\
I tried.. but there's no errors or anything o_o
Here's another MD5. Not sure where I found this at. (This is in a class btw)

Code:
Imports System.Security.Cryptography

Public Class CryptoClass
    
    <ComClass(Class1.ClassId, Class1.InterfaceId, Class1.EventsId)> Public Class Class1
        Public Const ClassId As String = "98349785-8BE2-4604-848D-F5B103D61715"
        Public Const InterfaceId As String = "36613EE9-125F-493d-9968-771E18C2226A"
        Public Const EventsId As String = "A036F02F-F87E-4548-A536-7DD7EA8E62B5"

        Const sKey As String = "MyKey"

        Public Function EncryptTripleDES(ByVal sIn As String) As String
            Dim DES As New TripleDESCryptoServiceProvider()
            Dim hashMD5 As New MD5CryptoServiceProvider()

            ' Compute the MD5 hash.
            DES.Key = hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(sKey))
            ' Set the cipher mode.
            DES.Mode = CipherMode.ECB
            ' Create the encryptor.
            Dim DESEncrypt As ICryptoTransform = DES.CreateEncryptor()
            ' Get a byte array of the string.
            Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(sIn)
            ' Transform and return the string.
            Return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
        End Function

        Public Function DecryptTripleDES(ByVal sOut As String) As String
            Dim DES As New TripleDESCryptoServiceProvider()
            Dim hashMD5 As New MD5CryptoServiceProvider()

            ' Compute the MD5 hash.
            DES.Key = hashMD5.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(sKey))
            ' Set the cipher mode.
            DES.Mode = CipherMode.ECB
            ' Create the decryptor.
            Dim DESDecrypt As ICryptoTransform = DES.CreateDecryptor()
            Dim Buffer As Byte() = Convert.FromBase64String(sOut)
            ' Transform and return the string.
            Return System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(Buffer, 0, Buffer.Length))
        End Function
    End Class
End Class
Well if he doesnt want anything that... perfect. MD5 sounds like a decent solution then (previous posts)
Thanks for the help guys, I will inform my friend to test these.
LOL, self written encryption algorithms (unless you're mathematician level: 1337) are going to suck. There's a reason that so few good encryption algorithms exist. The best you'll end up with is a half-assed cipher :/
I swear what is up with all the down syndrome in 2012? So when the user types his info and logs in, you want to encrypt it to a text file? You do realize by the time the program can encrypt the data, the key logger has already stolen 500$ from the guys Paypal account right?
Quote Originally Posted by Saltine View Post
I swear what is up with all the down syndrome in 2012? So when the user types his info and logs in, you want to encrypt it to a text file? You do realize by the time the program can encrypt the data, the key logger has already stolen 500$ from the guys Paypal account right?
Yes because encrypting stuff is only useful to prevent keyloggers.. (It isnt even...)

And keyloggers dont steal money... people do.
Quote Originally Posted by Saltine View Post
I swear what is up with all the down syndrome in 2012? So when the user types his info and logs in, you want to encrypt it to a text file? You do realize by the time the program can encrypt the data, the key logger has already stolen 500$ from the guys Paypal account right?
1. This is not a paypal account
2. It's just one step more for the person to get the password

This is just storing a password in a text file. Unless a keylogger takes all the users files, I doubt it would take a little text file.
Quote Originally Posted by Cryptonic View Post


1. This is not a paypal account
2. It's just one step more for the person to get the password

This is just storing a password in a text file. Unless a keylogger takes all the users files, I doubt it would take a little text file.
You obviously don't know what a keylogger is... It LOGS your keystrokes. So in order to ENCRYPT the password, the user has to STROKE his password. Meaning by the time your program can encrypt the password that the user has STROKED, the keylogger has already LOGGED the password. Lmfao...


EDIT: And the paypal thing was a joke... It was meant to get you to realize the above ^
Quote Originally Posted by J View Post

the user has to STROKE his password.
You make it sound like some kinky sex act.

@OP, encryption has nothing to do with keylogging. The reason one-way encryption is used on sensitive user data (such as passwords) is so that should a hacker manage to get into their system (be it a database or a plain text file), they aren't going to be presented with a long lovely list of plaintext passwords. However, it doesn't even sound like you have a centralized storage for passwords, you're just saving them on the users computer for no particular reason.

Edit: Here's a very basic little hash provider class I wrote:

Code:
Imports System.Security.Cryptography
Imports System.Text
Imports System.Reflection

Public Class HashProvider
    Public Shared Function Hash(ByVal data As String, ByVal algorithm As String) As String
        Return Hash(Encoding.ASCII.GetBytes(data), algorithm)
    End Function

    Public Shared Function Hash(ByVal data As Byte(), ByVal algorithm As String) As String
        Dim minfo = GetType(HashProvider).GetMethod(algorithm.ToLower(), BindingFlags.Static Or BindingFlags.NonPublic)
        If (minfo IsNot Nothing) Then
            Return minfo.Invoke(Nothing, New Object() {data}).ToString()
        Else
            Throw New NotSupportedException("Hash algorithm is not yet supported")
        End If
    End Function

    Private Shared Function sha1(ByVal data As Byte()) As String
        Return GetHash(Of SHA1CryptoServiceProvider)(data, 40)
    End Function

    Private Shared Function md5(ByVal data As Byte()) As String
        Return GetHash(Of MD5CryptoServiceProvider)(data, 32)
    End Function

    Private Shared Function sha256(ByVal data As Byte()) As String
        Return GetHash(Of SHA256CryptoServiceProvider)(data, 64)
    End Function

    Private Shared Function sha512(ByVal data As Byte()) As String
        Return GetHash(Of SHA512CryptoServiceProvider)(data, 128)
    End Function

    'This function actually does most of the work.
    Private Shared Function GetHash(Of T As {New, HashAlgorithm})(ByVal data As Byte(), ByVal len As Integer) As String
        Using algo As New T()
            Return algo.ComputeHash(data).Aggregate(New StringBuilder(len), Function(sb, b) sb.Append(b.ToString("x"))).ToString()
        End Using
    End Function
End Class
Very easy to use:

Code:
Dim md5Hash As String = HashProvider.Hash("hello world", "md5")
Dim sha512Hash As String = HashProvider.Hash("something", "sha512")
Quote Originally Posted by Jason View Post
You make it sound like some kinky sex act.
LOL

Quote Originally Posted by Jason View Post
@OP, encryption has nothing to do with keylogging. The reason one-way encryption is used on sensitive user data (such as passwords) is so that should a hacker manage to get into their system (be it a database or a plain text file), they aren't going to be presented with a long lovely list of plaintext passwords. However, it doesn't even sound like you have a centralized storage for passwords, you're just saving them on the users computer for no particular reason.
Exactly, but, if you say that I'm saving the passwords on the users computer for no reason... then how should I do it? This isn't a login system for any of my stuff, it's for a game. But, I suppose I could look into MySQL and see what I can do...
Quote Originally Posted by Cryptonic View Post


LOL



Exactly, but, if you say that I'm saving the passwords on the users computer for no reason... then how should I do it? This isn't a login system for any of my stuff, it's for a game. But, I suppose I could look into MySQL and see what I can do...
If each user has their own local "database", what's the point?
Posts 16–30 of 39 · Page 2 of 3

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?