Envoyé par
Qwazerty
Mon code proviens aussi d'un code VB qui marche et que je cherche a traduire en Delphi.
Voici la declaration que j'ai :
Private Declare Function CryptDecrypt Lib "advapi32.dll" (ByVal hKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByRef pbData As Any, pdwDataLen As Long) As Long
Sinon voici le code d'appel :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| Public Function Decrypt(ByVal szKey As String, ByRef pData() As Byte, ByRef dwSize As Long) As Long
Dim lResult As Long
lResult = UpdateKey(szKey)
If lResult = 0 Then
If CBool(CryptDecrypt(m_hKey, 0, 1, 0, pData(0), dwSize)) = True Then
ReDim Preserve pData(dwSize)
Decrypt = 0
Exit Function
End If
Else
Decrypt = lResult
Exit Function
End If
Decrypt = Err.LastDllError
End Function |
et le code d'appel de cette fonction (chargemetn du fichier)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| Private Sub Decrypt_Click()
Dim data() As Byte
Dim lFileLength As Long
Dim File As Integer
Dim b As CProtect
Dim lResult As Long
lFileLength = FileLen(FileName.Text)
ReDim data(lFileLength)
File = FreeFile
Open FileName.Text For Binary As #File
Get #File, 1, data
Close File
Set b = New CProtect
lResult = b.Decrypt(PUID.Text, data, lFileLength)
If lResult = 0 Then
Text2.Text = data
Else
Text2.Text = "Failed to Decode the file." & vbCrLf & "Error: " & lResult
End If
End Sub |
et pour finir un post ou j'ai posté le code declaratif de l'aide du SDK delphi : ici
Je sens que je suis pret du but ... et que le probleme viendrais de la transmission de ce code la ....
Si quelqu'un peut m'y aider ca serait cool
Partager