none
RC4 CryptoAPI to PHP port RRS feed

  • Question

  • Hello, I am trying to emulate a working CryptoAPI RC4 encrypt/decrypt routine in PHP.  When doing so, I've run into a problem trying to recreate the CryptCreateHash +CryptHashData process.  I'm trying to figure out how CryptoAPI orders/combines the raw data when calling CryptHashData multiple times.  

    For example:

    // I create the hash variable, then hash a binary string using CryptHashData and then hash a secret using CryptHashData again.

    BYTE baKeyRandom[10] = {87,253, ...};
    ::CryptCreateHash(hCryptProv, CALG_MD5, 0, 0, &hSaveHash);
    ::CryptHashData(hSaveHash, baKeyRandom, (DWORD)sizeof(baKeyRandom), 0);
    ::CryptHashData(hSaveHash, (LPBYTE)T2CW(pszSecret), (DWORD)_tcslen(pszSecret) * sizeof(WCHAR), 0); 

    Then in PHP I'm trying to do something similar

    // server key secret
    $secret = 'ABCDEF-G...';

    // random byte string
    $random = pack('c*', 87,253, ...);

    // simple concat does not work to generate an MD5 key
    $key = md5($random.$secret);

    So the question is how to emulate this step and match the C++ CryptoApi MD5 hash key in php

    • Moved by Jack Zhang - AAA Monday, December 24, 2018 6:05 AM this issue is more related to PHP
    Friday, December 21, 2018 1:38 PM

All replies

  • Hi kguller,

    Thanks for posting here.

    Refer to your description, your issue is about the PHP. Since our forum is to discuss the C++ development, I will help you move this thread to the off-topic forum.

    Thank you for your understanding.

    Best regards,

    Jack


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 24, 2018 6:04 AM