Need digest output from HMAC sha-256
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!