PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV 2024 → Why does Hash and Base64 have different results(is it wrong?)
Why does Hash and Base64 have different results(is it wrong?)
Iniciado por Mick, jan., 13 2021 5:16 AM - 3 respostas
Publicado em janeiro, 13 2021 - 5:16 AM
windev code:
secretKey is string= "Gu5t9xGARNpq86cd98joQYCN3*******"
srcStr is string = "GETcvm.tencentcloudapi.com/?Action=DescribeInstances&InstanceIds.0=ins-09dx96dg&Limit=20&Nonce=11886&Offset=0&Region=ap-guangzhou&SecretId=AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******&Timestamp=1465185768&Version=2017-03-12"
signStr is string = Encode(HashString(HA_HMAC_SHA_160,srcStr,secretKey),encodeBASE64)
trace(signStr) //the result is "5PaiqVPaSxwQrIfjSGO8wQ+nozE="

php code:
$secretKey = 'Gu5t9xGARNpq86cd98joQYCN3*******';
$srcStr = 'GETcvm.tencentcloudapi.com/?Action=DescribeInstances&InstanceIds.0=ins-09dx96dg&Limit=20&Nonce=11886&Offset=0&Region=ap-guangzhou&SecretId=AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******&Timestamp=1465185768&Version=2017-03-12';
$signStr = base64_encode(hash_hmac('sha1', $srcStr, $secretKey, true));
echo $signStr;
//the resule is "zmmjn35mikh6pM3V7sUEuX4wyYM="

the result is diffrent, and the PHP result is Official.Why???
Membro registado
14 mensagems
Publicado em janeiro, 14 2021 - 6:52 AM
It's simple: the functions Hash and Encode are two different things. Hash: the source string is unrecoverable. Encode: the source string is recoverable.

--
Gunter Predl
paypal@windev.at
Publicado em janeiro, 15 2021 - 2:29 PM
HashString treats the input strings as a raw bytes, therefore the ANSI vs UNICODE character encoding is critical. Change the secretKey and srcStr declarations to 'ANSI String' and your code will produce the same output as the php version.
Publicado em janeiro, 26 2021 - 5:45 AM
the problem was solved.the hashstring string,i use stringtouft8