I am trying to generate a signature using Elixir, which has the same meaning as PHP.
For example, code in PHP
$signature = base64_encode(hash_hmac("sha256", "abc", "def"));
and the output will be
Mzk3ZjQ2NzM0MWU0ZDc4YzQ3NDg2N2VmMzI2MWNkYjQ2YzBlMTAzNTFlOWE5ODk5NjNlNmNiMmRjZTQwZWU1ZA==
How to create a signature that has the same meaning in Elixir. I tried something like below
iex(9)> :crypto.hmac(:sha256, "abc", "def") |> Base.encode64 │ "IOvA8JNERwE081BA9j6pix2OQUISlJ7lxQBCnRXqsIE=" iex(10)> :crypto.hash(:sha256, :crypto.hmac(:sha256, "abc", "def")) |> Base.encode64 │ "dxGiPN6KqBJrtS2wlC4tnJXwUsWf4u1LPDtDFK+VT5A="
or i switch the position of abc and def
iex(11)> :crypto.hash(:sha256, :crypto.hmac(:sha256, "def", "abc")) |> Base.encode64 │ "b+3P5oHu8e6HIlJe2MzcGhKm7tCcF/NE5wPIbEhrFGU=" iex(12)> :crypto.hmac(:sha256, "def", "abc") |> Base.encode64 │ "OX9Gc0Hk14xHSGfvMmHNtGwOEDUempiZY+bLLc5A7l0="
But not one of them has the same meaning. Can someone tell me how to do it right?
source share