Passwort verschlüsseln

    • VB6

    Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Malcolm.

      Passwort verschlüsseln

      Das ist zwar nicht richtig verschlüsselt, aber nicht jeder DAU kann das lesen. Es gibt Programmierer, die schreiben Passwörter unverschlüsselt in die Datenbank!!
      Ich finde besser so als garnicht verschlüsselt

      Visual Basic-Quellcode

      1. '###im programm ver-und entschlüsseln
      2. 'Dim re As String
      3. 're = Chiffre("teststring zum verschlüsseln", 128)
      4. '###im programm ver-und entschlüsseln
      5. '###im Modul
      6. Public Function Chiffre _
      7. (Original As String, bKey As Byte) As String
      8. Dim i As Long
      9. Dim bCode As Byte
      10. Dim bResult As Byte
      11. Chiffre = ""
      12. For i = 1 To Len(Original)
      13. bCode = Asc(Mid(Original, i, 1))
      14. bResult = bCode Xor bKey
      15. Chiffre = Chiffre & Chr(bResult)
      16. Next i
      17. End Function
      ;)


      Edit by Agent: vb-tag eingefügt

      Wer suchet der findet, wer draufklickt kommt auf den wahren Pfad!

      Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „FlashTek“ ()


      ' Text in Verbindung mit einem Passwort verschlüsseln

      Visual Basic-Quellcode

      1. Public Function EncodeString(ByVal strToEncode As String, _
      2. ByVal strPassword As String) As String
      3. Dim strResult As String
      4. Dim i As Long
      5. Dim cfc() As Integer
      6. ReDim cfc(1 To Len(strPassword))
      7. For i = 1 To UBound(cfc)
      8. cfc(i) = Asc(Right(strPassword, _
      9. Len(strPassword) - i + 1))
      10. Next i
      11. For i = 1 To Len(strToEncode)
      12. strResult = strResult & _
      13. Chr(addToIndex(Asc(Right(strToEncode, _
      14. Len(strToEncode) - i + 1)), VirtPos(i, cfc)))
      15. Next i
      16. EncodeString = strResult
      17. End Function
      18. ' Text in Verbindung mit einem Passwort entschlüsseln
      19. Public Function DecodeString(ByVal strToDecode As String, _
      20. ByVal strPassword As String) As String
      21. Dim strResult As String
      22. Dim i As Long
      23. Dim cfc() As Integer
      24. ReDim cfc(1 To Len(strPassword))
      25. ReDim ttc(1 To Len(strToDecode))
      26. For i = 1 To UBound(cfc)
      27. cfc(i) = Asc(Right(strPassword, _
      28. Len(strPassword) - i + 1))
      29. Next i
      30. For i = 1 To Len(strToDecode)
      31. strResult = strResult & _
      32. Chr(GetOfIndex(Asc(Right(strToDecode, _
      33. Len(strToDecode) - i + 1)), VirtPos(i, cfc)))
      34. Next i
      35. DecodeString = strResult
      36. End Function
      37. ' Hilfsfunktionen
      38. Private Function VirtPos(i As Long, _
      39. a() As Integer) As Integer
      40. If i > UBound(a) Then
      41. VirtPos = VirtPos(i - UBound(a), a)
      42. Else
      43. VirtPos = a(i)
      44. End If
      45. End Function
      46. Private Function addToIndex(i As Integer, _
      47. j As Integer) As Integer
      48. If i + j > 255 Then
      49. addToIndex = i + j - 255
      50. Else
      51. addToIndex = i + j
      52. End If
      53. End Function
      54. Private Function GetOfIndex(i As Integer, _
      55. j As Integer) As Integer
      56. If i - j < 0 Then
      57. GetOfIndex = i - j + 255
      58. Else
      59. GetOfIndex = i - j
      60. End If
      61. End Function



      So, das ist eine "richtige" (und recht sichere)Verschlüsselung:

      Beispiel
      Plazieren Sie auf die Form drei Textboxen (txtToEncode, txtPassword und txtResult), sowie zwei Command-Buttons (cmdEncode und cmdDecode). Beim Klicken auf den ersten CommandButton wird der Text in txtToEncode in Verbindung mit dem in txtPassword eingetragenen Passwort verschlüsselt und in der TextBox txtResult angezeigt. Beim Klicken auf den zweiten CommandButton wird der Ergebnis-Text wieder entschlüsselt und ebenfalls in txtResult angezeigt.

      Visual Basic-Quellcode

      1. Private Sub cmdEncode_Click()
      2. ' Verschlüsseln
      3. txtResult.Text = EncodeString(txtToEncode.Text, _
      4. txtPassword.Text)
      5. End Sub
      6. Private Sub cmdDecode_Click()
      7. ' Entschlüsseln
      8. txtResult.Text = DecodeString(txtResult.Text, _
      9. txtPassword.Text)
      10. End Sub


      mfG,

      Malcolm


      Edit by Agent: vb-tag eingefügt

      Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Agent“ ()