Your call of DataHash creates the hash considering the class of the obejct. You want to get the hash for the values only.
challenge = 'c100b894-1729-464d-ace1-52dbce11db42';
Opt.Method = 'SHA-256';
Opt.Input = 'ascii';
hash_digest = DataHash(challenge, Opt)
DataHash(challenge, struct('Method','SHA-256'))
DataHash(challenge.', struct('Method','SHA-256'))
By the way, DataHash is an overkill here. Leaner:
Engine = java.security.MessageDigest.getInstance('SHA-256');
Engine.update(uint8(challenge(:)));
Hash = typecast(Engine.digest, 'uint8')
And for HMAC:
BlockSize = 128;
KeySize = numel(Key);
Key = uint8(Key);
ipad(1:BlockSize) = uint8(54);
ipad(1:KeySize) = bitxor(uint8(54), Key);
opad(1:BlockSize) = uint8(92);
opad(1:KeySize) = bitxor(uint8(92), Key);
Engine2 = java.security.MessageDigest.getInstance('SHA-512');
Engine2.update(ipad);
Engine2.update(uint8(Msg));
iHash = typecast(Engine2.digest, 'uint8');
Engine2.update(opad);
Engine2.update(iHash);
HMAC = typecast(Engine2.digest, 'uint8');
Best Answer