#include <winapi.au3>
#cs
BOOL WINAPI CryptProtectData(
_In_ DATA_BLOB *pDataIn,
_In_ LPCWSTR szDataDescr,
_In_ DATA_BLOB *pOptionalEntropy,
_In_ PVOID pvReserved,
_In_opt_ CRYPTPROTECT_PROMPTSTRUCT *pPromptStruct,
_In_ DWORD dwFlags,
_Out_ DATA_BLOB *pDataOut
);
#ce
Global $tagDATA_BLOB = 'DWORD cbData;PTR pbData'
Global $g_Crypt32Dll = DllOpen('Crypt32.dll')
Local $sOutText = ''
If RDP_Encrypt('freedom','psw',$sOutText) Then MsgBox(64,'Result',$sOutText)
DllClose($g_Crypt32Dll)
Func RDP_Encrypt($szDataInput,$szDataDescr,ByRef $sOut)
Local $nLen = StringLen($szDataInput) * 2
Local $tBuffer = DllStructCreate(StringFormat('wchar[%d]', $nLen+1))
Local $tDATA_BLOB = DllStructCreate($tagDATA_BLOB)
Local $tDataDescr = DllStructCreate(StringFormat('wchar[%d]',2*StringLen($szDataDescr)+1))
Local $tDataOut = DllStructCreate($tagDATA_BLOB)
Local $tBufferOut,$nRet
DllStructSetData($tBuffer, 1, $szDataInput)
DllStructSetData($tDATA_BLOB, 'cbData', $nLen)
DllStructSetData($tDATA_BLOB, 'pbData', DllStructGetPtr($tBuffer))
DllStructSetData($tDataDescr,1,$szDataDescr)
$nRet = DllCall($g_Crypt32Dll, 'BOOL', 'CryptProtectData', 'ptr', DllStructGetPtr($tDATA_BLOB), 'ptr', DllStructGetPtr($tDataDescr), 'ptr', 0, 'ptr', 0, 'ptr', 0, 'DWORD', 0, 'ptr', DllStructGetPtr($tDataOut))
If @error Then
ConsoleWrite(StringFormat('DllCall Error:%d\n', @error))
Return False
EndIf
If $nRet[0] = 0 Then
ConsoleWrite(StringFormat('call CryptProtectData Error:%d\nErrorMessage:%s\n', _WinAPI_GetLastError(),_WinAPI_GetLastErrorMessage()))
Return False
EndIf
$tBufferOut = DllStructCreate(StringFormat('BYTE[%d]',DllStructGetData($tDataOut,'cbData')),DllStructGetData($tDataOut,'pbData'))
$sOut = ''
For $i = 0 To DllStructGetSize($tBufferOut)
$sOut &= StringFormat('%02X',DllStructGetData($tBufferOut,1,$i+1))
Next
_WinAPI_LocalFree(DllStructGetData($tDataOut,'pbData'));When you have finished using the DATA_BLOB structure, free its pbData member by calling the LocalFree function.
Return True
EndFunc