Here is the desription of what I need to do: https://cryptofacilities.zendesk.com/hc/en-us/articles/360000642493-Sign-Challenge-Web-Socket-API-
1) We have determined input:
challenge = 'c100b894-1729-464d-ace1-52dbce11db42';apiSecret = '7zxMEF5p/Z8l2p2U7Ghv6x14Af+Fx+92tPgUdVQ748FOIrEoT9bgT+bTRfXc5pz8na+hL/QdrCVG7bh9KpT0eMTm';
2) We need to receive an expected output:
signed_output = '4JEpF3ix66GA2B+ooK128Ift4XQVtc137N9yeg4Kqsn9PI0Kpzbysl9M1IeCEdjg0zl00wkVqcsnG4bmnlMb3A==';
3) Here are steps of how we should encrypt it:
- Hash the challenge with the SHA-256 algorithm
- Base64-decode your api_secret
- Use the result of step 2 to hash the result of step 1 with the HMAC-SHA-512 algorithm
- Base64-encode the result of step 3
My code:
import matlab.net.* % 1. Hash the challenge with the SHA-256 algorithm
hash_digest = DataHash(challenge, struct('Method','SHA-256')); % 2. Base64-decode your api_secret
secret_decoded = base64decode(apiSecret); % 3. Use the result of step 2 to hash the result of step 1 with the HMAC-SHA-512 algorithm
hmac_digest = HMAC(secret_decoded,hash_digest,'SHA-512'); % 4. Base64-encode the result of step 3
signed_output = base64encode(hmac_digest);
I am using these functions:
The result is wrong. Could you please help me to fix it?
Best Answer