MATLAB Answers


Need digest output from HMAC sha-256

Asked by Martin
on 20 Mar 2018
Hello. I need to Generate a HMAC-key by base64-decoding a given key (resulting in 64 bytes). Then I need to use the HMAC-key to create a sha256 HMAC with a given string (I should expect a digest output). Last I need to convert the result (the signature) into a base64-encoded result.
For some reason I do something wrong...
% base64-decoding the key
key_uint8 = uint8(key);
key = typecast(org.apache.commons.codec.binary.Base64.decodeBase64(key_uint8), 'uint8')';
% do the HMAC
Signature = HMAC(key,string,'SHA-256');
% base64-encoded result
I use the HMAC Hash Message Authentication Code Function by Peter Grunnet Wang.
I do not think it is the base64 decoding and encoding that goes wrong. I think it is the HMAC since I do not get a digest output. Does anyone know a way around this ?


Sign in to comment.

0 Answers