Menú

Mostrar Mensajes

Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.

Mostrar Mensajes Menú

Mensajes - nemit

#1
Hi Karcrack.

Thx for kInvoke.

Everything runs fine in the code except the commentet Invoke Calls.
Maybe you know what im doing wrong?


Código (vb) [Seleccionar]
Option Explicit

Private Declare Function CryptEncrypt Lib "advapi32.dll" (ByVal hKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByVal pbData As String, pdwDataLen As Long, ByVal dwBufLen As Long) As Long
Private Declare Function CryptDecrypt Lib "advapi32.dll" (ByVal hKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByVal pbData As String, pdwDataLen As Long) As Long
Private Declare Function CryptHashData Lib "advapi32.dll" (ByVal hHash As Long, ByVal pbData As String, ByVal dwDataLen As Long, ByVal dwFlags As Long) As Long

Private Const PROV_RSA_AES      As Long = 24
Private Const CRYPT_NEWKEYSET   As Long = 8
Private Const CALG_AES_256      As Long = 26128
Private Const CALG_SHA_512      As Long = 32782
Private Const CRYPT_CREATE_SALT As Long = &H4

Private Type OSVERSIONINFO
        dwOSVersionInfoSize     As Long
        dwMajorVersion          As Long
        dwMinorVersion          As Long
        dwBuildNumber           As Long
        dwPlatformId            As Long
        szCSDVersion            As String * 128
End Type

Private Const sAdvapi As String = "advapi32.dll"
Private Const sKernel As String = "kernel32.dll"


Public Function EnDecodeAES(ByVal sData As String, ByVal sPassword As String, ByVal bEncrypt As Boolean) As String
   
Dim hHash As Long
Dim hKey As Long
Dim hCryptProv As Long
Dim lData As Long
Dim sGetServiceProvider As String
Dim OS As OSVERSIONINFO

    OS.dwOSVersionInfoSize = Len(OS)
    Call Invoke(sKernel, &HC75FC483, VarPtr(OS))
   
    If OS.dwMajorVersion & OS.dwMinorVersion >= 60 Then
        sGetServiceProvider = "Microsoft Enhanced RSA and AES Cryptographic Provider"
    Else
        sGetServiceProvider = "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
    End If
   
    Call Invoke(sAdvapi, &H43C28BF0, VarPtr(hCryptProv), 0, StrPtr(sGetServiceProvider), PROV_RSA_AES, CRYPT_NEWKEYSET)
    Call Invoke(sAdvapi, &H43C28BF0, VarPtr(hCryptProv), 0, StrPtr(sGetServiceProvider), PROV_RSA_AES, 0&)
    Call Invoke(sAdvapi, &H4105A130, hCryptProv, CALG_SHA_512, 0, 0, VarPtr(hHash))
   
    'Private Declare Function CryptHashData Lib "advapi32.dll" (ByVal hHash As Long, ByVal pbData As String, ByVal dwDataLen As Long, ByVal dwFlags As Long) As Long
    'Call Invoke(sAdvapi, &HC2122629, hHash, sPassword, Len(sPassword), 0)
    ' without Invoke
    Call CryptHashData(hHash, sPassword, Len(sPassword), 0)
   
    Call Invoke(sAdvapi, &HC2122629, hHash, StrPtr(sPassword), Len(sPassword), 0)
    Call Invoke(sAdvapi, &HB56D274A, hCryptProv, CALG_AES_256, hHash, CRYPT_CREATE_SALT, VarPtr(hKey))
   
    lData = Len(sData)
    If bEncrypt Then
        sData = sData & Space(16)
       
        'Private Declare Function CryptEncrypt Lib "advapi32.dll" (ByVal hKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByVal pbData As String, pdwDataLen As Long, ByVal dwBufLen As Long) As Long
        'Call Invoke(sAdvapi, &HD9242588, hKey, 0, 1, 0, sData, VarPtr(lData), Len(sData))
        ' without Invoke
        Call CryptEncrypt(hKey, 0, 1, 0, sData, lData, Len(sData))
       
    Else
       
        'Private Declare Function CryptDecrypt Lib "advapi32.dll" (ByVal hKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByVal pbData As String, pdwDataLen As Long) As Long
        'Call Invoke(sAdvapi, &H59202584, hKey, 0, 1, 0, sData, VarPtr(lData))
        ' without Invoke
        Call CryptDecrypt(hKey, 0, 1, 0, sData, lData)
       
    End If
   
    EnDecodeAES = Left(sData, lData)
    Call Invoke(sAdvapi, &H25D4AE7A, hHash)
    Call Invoke(sAdvapi, &H95E24580, hKey)
    Call Invoke(sAdvapi, &H5AE8E894, hCryptProv, 0)
End Function