Ik zit met het volgende probleem. Bij een bedrijf draait een VB applicatie waatbij de username en wachtwoorden geencrypt in de MySQL database worden opgeslagen. Nu moet voor de website gebruik gemaakt worden van dezelfde database en dus ook van hetzelfde Encrypt/Decrypt Algoritme. Nu ben ik al een tijd bezig om het script om te zetten maar ik krijg het niet voor elkaar om php functies te maken die hetzelfde doen als de VB functies (heb helaas ook niet echt veel kennis van VB). De code van de VB functies staat hieronder:
Zou iemand mij op weg kunnen helpen met het omzetten van deze functies?
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
| Public Function Encrypt(SourceData As String, Password As String, Optional ExpandedOutput As Boolean = False) As String ' Decrypt an Encrypted string using the Encrypt ' returns a string that can be saved into a database ' MyString = GF.Decrypt(GF.Encrypt("This is my string", "My Password"), "My Password") ' optionally ExpandedOutput will return a string with no binary data for saving in a database ' or emailing. Dim s$ Dim PC As Long Dim lc As Long Dim lOutCount As Long Dim lChar As Long lc = 1 If ExpandedOutput Then lc = 2 End If s$ = Space$(Len(SourceData) * lc) If Len(s$) = 0 Then Exit Function lOutCount = 1 For lc = 1 To Len(SourceData) PC = PC + 1 If PC > Len(Password) Then PC = 1 End If lChar = Asc(Mid(SourceData, lc, 1)) Xor Asc(Mid$(Password, PC, 1)) If ExpandedOutput Then ' Turn lchar into hex Mid$(s$, lOutCount, 1) = Chr(65 + (lChar And &HF0) / &H10) Mid$(s$, lOutCount + 1, 1) = Chr(65 + (lChar And &HF)) lOutCount = lOutCount + 2 Else Mid$(s$, lOutCount, 1) = Chr(lChar) lOutCount = lOutCount + 1 End If Next Encrypt = s$ End Function Public Function Decrypt(EncryptedData As String, Password As String, Optional ExpandedInput As Boolean = False) As String ' Decrypt an Encrypted string using the Encrypt ' returns a string that can be saved into a database ' MyString = GF.Decrypt(GF.Encrypt("This is my string", "My Password"), "My Password") Dim s$ Dim lc As Long Dim PC As Long Dim lB1 As Long Dim lB2 As Long Dim lOutCount As Long Dim lChar As Long If Len(EncryptedData) = 0 Then Exit Function If Not ExpandedInput Then Decrypt = Encrypt(EncryptedData, Password) Exit Function End If s$ = Space(Len(EncryptedData) * 0.5) lc = 1 lOutCount = 1 ' convert aphap data to binary data Do While lc < Len(EncryptedData) lB1 = Asc(Mid(EncryptedData, lc, 1)) - 65 lB2 = Asc(Mid(EncryptedData, lc + 1, 1)) - 65 lc = lc + 2 Mid$(s$, lOutCount, 1) = Chr((lB1 * 16) + lB2) lOutCount = lOutCount + 1 Loop Decrypt = Encrypt(s$, Password) End Function |
Zou iemand mij op weg kunnen helpen met het omzetten van deze functies?