Hallo Zusammen
Ich habe mir folgende Klasse gebastelt:
Ich habe eine Form mit dem Namen "frm_main"
Dort wird mein String verschlüsselt bzw. entschlüsselt.
Wie ihr seht habe ich meinen Salt"qerq34234234$$234$$$234234234234" hardgecodet im VB.NET Code.
Könnt ihr mir Anregungen geben wie ich das besser machen kann?
Denn mir ist klar, dass wenn man den Salt im Quellcode hat dies nicht optimal ist.
Freundliche Grüsse
Lingo
Ich habe mir folgende Klasse gebastelt:
VB.NET-Quellcode
- Public Class AES
- Public Shared Function Encrypt(ByVal input As String, ByVal pass As String) As String
- Dim AES As New System.Security.Cryptography.RijndaelManaged
- Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
- Dim encrypted As String = ""
- Try
- Dim hash(31) As Byte
- Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
- Array.Copy(temp, 0, hash, 0, 16)
- Array.Copy(temp, 0, hash, 15, 16)
- AES.Key = hash
- AES.Mode = Security.Cryptography.CipherMode.ECB
- Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
- Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
- encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
- Return encrypted
- Catch ex As Exception
- End Try
- End Function
- Public Shared Function Decrypt(ByVal input As String, ByVal pass As String) As String
- Dim AES As New System.Security.Cryptography.RijndaelManaged
- Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
- Dim decrypted As String = ""
- Try
- Dim hash(31) As Byte
- Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
- Array.Copy(temp, 0, hash, 0, 16)
- Array.Copy(temp, 0, hash, 15, 16)
- AES.Key = hash
- AES.Mode = Security.Cryptography.CipherMode.ECB
- Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateDecryptor
- Dim Buffer As Byte() = Convert.FromBase64String(input)
- decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
- Return decrypted
- Catch ex As Exception
- End Try
- End Function
- End Class
Ich habe eine Form mit dem Namen "frm_main"
VB.NET-Quellcode
- Public Class frm_main
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- txtEncryptedText.Text = AES.Encrypt(txtOriginalText.Text, "qerq34234234$$234$$$234234234234")
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- MessageBox.Show(AES.Decrypt(txtEncryptedText.Text, "qerq34234234$$234$$$234234234234"))
- End Sub
- End Class
Dort wird mein String verschlüsselt bzw. entschlüsselt.
Wie ihr seht habe ich meinen Salt"qerq34234234$$234$$$234234234234" hardgecodet im VB.NET Code.
Könnt ihr mir Anregungen geben wie ich das besser machen kann?
Denn mir ist klar, dass wenn man den Salt im Quellcode hat dies nicht optimal ist.
Freundliche Grüsse
Lingo
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Lingo“ ()