drl37530 2018-12-21 14:00
浏览 62

RC4 CryptoAPI到PHP端口

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.

I have tried to concatenate the two input values to the key in different ways as well as reverse the byte order, but I'm not sure how to emulate the exact steps that CryptHashData performs.

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, I have been unable to decrypt using this key or match the php key against the C++ exported key

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥15 Oracle触发器记录修改前后的字段值
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题