dec2bin, hex2dec and co don't work the way you think they're doing.
>> hex2dec(header_hex)
ans =
1.78220342011972e+190
You get just one number. Not a decimal string. You would have to first reshape your hex header into rows of 2 characters (8 bits) for it to work. As for the conversions to binary, I don't understand what you're trying to do. They're not necessary.
Here's how to do it:
header_hex = ['01000000',...
'81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000',...
'e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b',...
'c7f5d74d',...
'f2b9441a',...
'42a14695'];
header = hex2dec(reshape(header_hex, 2, [])');
md = java.security.MessageDigest.getInstance('SHA-256');
pass1 = typecast(md.digest(header), 'uint8');
pass2 = typecast(md.digest(pass1), 'uint8');
sprintf('%02x', pass2)
Best Answer