Is there any way to create a HmacSHA256 signature of a string in php?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Use
hash_hmac
:Where
$secret
is your key.The
hash_hmac()
function could help, here :For example, the following portion of code :
Gives the following output :
And, to get the list of hashing algorithms that can be used, see
hash_algos()
.Here is an example of datatrans transaction signing (swiss e-payment solution) before call PSP with HMAC-SHA-256.
Hope it could help some developers.
Note: the merchant ID and HMAC key are both from Datatrans documentation available here : https://admin.sandbox.datatrans.com/showcase/doc/Technical_Implementation_Guide.pdf