function [h,hx,Engine]=hash(str,hfun)
% hash <Hash string str(uint8) to array of uint8, using hash function hfun['md5']>
% Usage:: [h,[hexst],[Engine]=hash(str,hfun['md5'])
%
% convert to hexstr=flat(dec2hex(hash(str,'sha-256'))')'

% revision history:
% 05/26/19 Mark D. Shattuck <mds> hash.m

%% Parse Input
if(~exist('hfun','var') || isempty(hfun))
	hfun='md5';
end

%% Main

Engine=java.security.MessageDigest.getInstance(hfun);
h=typecast(Engine.digest(uint8(str)), 'uint8');

if(nargout>1)
  hx=flat(dec2hex(h)')';
end

