Home > Software engineering > Crypt32 call CryptStringToBinaryA wrong.. We help to find the reason...
Crypt32 call CryptStringToBinaryA wrong.. We help to find the reason...
Time:09-30
Private Declare Function CryptBinaryToStringA Lib "crypt32. DLL" (ByRef pbBinary () As Byte, ByVal cbBinary As Long, ByVal dwFlags As Long, ByVal pszString As String, ByVal pcchString As String) As Long Private Declare Function CryptBinaryToStringW Lib "crypt32. DLL" (ByRef pbBinary () As Byte, ByVal cbBinary As Long, ByVal dwFlags As Long, ByVal pszString As String, ByVal pcchString As String) As Long Private Declare Function CryptStringToBinaryA Lib "crypt32. DLL" (ByVal pszString As Long, ByVal cchString As Long, ByVal dwFlags As Long, ByVal pbBinary As Long, ByVal pcbBinary As Long, ByVal pdwSkip As Long, ByVal pdwFlags As Long) As Long Private Const CRYPT_STRING_BASE64=& amp; H1
'the static void Decode (const char * sBase64, STD: : vector & Decoded_data) '{ 'decoded_data. The clear ();
'if (sBase64) '{ 'DWORD nNeed=0; 'CryptStringToBinaryA (sBase64, 0, CRYPT_STRING_BASE64, NULL, & amp; NNeed, NULL, NULL); 'if (nNeed) '{ 'decoded_data. Resize (nNeed); 'CryptStringToBinaryA (sBase64, 0, CRYPT_STRING_BASE64, & amp; Decoded_data [0], & amp; NNeed, NULL, NULL); '} '} '} Private Sub Command1_Click () Decode "5 oir5piv5zwk "End Sub The Public Function Decode (sBase64 As String) Dim nNeed As Long Call CryptStringToBinaryA (ByVal StrPtr (sBase64), 0, CRYPT_STRING_BASE64, 0 & amp; NNeed& , 0 & amp; , 0 & amp;) 'the wrong operation. 'MsgBox nNeed& End the Function
with CryptStringToBinaryW returns 0 - -!
CodePudding user response:
Private Declare Function CryptStringToBinary W Lib "crypt32. DLL" (ByVal pszString As Long, ByVal cchString As Long, ByVal dwFlags As Long, ByVal pbBinary As Long, Byref pcbBinary As Long, ByVal pdwSkip As Long, ByVal pdwFlags As Long As Long) Using the W