Need digest output from HMAC sha-256

조회 수: 6 (최근 30일)
Martin
Martin 2018년 3월 20일
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...
string='abcdefgh';
key='5jM8liyKv5iLiTu8e5DL2cjjM9K2XhWNKiq9y5ad4JVrhRZF1PKqX5yufwrMbrB7BjoToapiInoDU7jfJkXDHQ==';
% 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
Signature_uint8=uint8(Signature);
Signature=char(org.apache.commons.codec.binary.Base64.encodeBase64(Signature_uint8))';
I use the HMAC Hash Message Authentication Code Function by Peter Grunnet Wang. https://se.mathworks.com/matlabcentral/fileexchange/46182-hmac-hash-message-authentication-code-function
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 ?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by