PROFESSIONAL NEWSGROUPS
WINDEV
,
WEBDEV
and
WINDEV Mobile
Home
|
Recent messages
|
Connect
|
Sign out
|
English
Home
→
WINDEV 2024
→
Why does Hash and Base64 have different results(is it wrong?)
Why does Hash and Base64 have different results(is it wrong?)
Started by Mick, Jan., 13 2021 5:16 AM - 3 replies
Connect yourself…
Mick
#1
Posted on January, 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???
Report
0
0
Guenter
#2
Registered member
14 messages
Posted on January, 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
Report
0
0
Tucat
#3
Posted on January, 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.
Report
0
0
Mick
#4
Posted on January, 26 2021 - 5:45 AM
the problem was solved.the hashstring string,i use stringtouft8
Report
0
0
→ Go back to WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (earlier versions)
Français
English
Español
Portuguesa
Close this window
Search type
Only topics
All the messages
Search period
Any time
Past hour
Past 24 hours
Past week
Past month
Past year
Cancel
Preview of your message
Adding an image
Import an image from a URL
Send an image from a file of your disk
Drop a file or click "Browse..."
or
Cancel
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Text