16 진수 문자열로 표시된 일부 데이터에 대해 matlab에서 RIPEMD160 해시를 계산하려고합니다. 나는 다음과 같은 자바 클래스를 발견하고 다음 코드는 해싱 문자열을 MATLAB에서 완벽하게 작동 1.6Matlab의 RIPEMD160 해시
http://developer.nokia.com/Community/Wiki/RIPEMD160_encryption_in_JavaME
JVM을 위해 컴파일 :
clear all
% add folder with class file to java path
functions_folder = strcat(pwd,filesep,'functions');
javaaddpath(functions_folder)
% string to hash
string_to_hash = 'test12345';
% convert to java String
str_to_hash_java = javaObject('java.lang.String',uint8(string_to_hash));
% pass in string and convert output to char array
mystr = char(RIPEMD160.RIPEMD160String(str_to_hash_java))
이제 내 문제는 내가 몇 가지를 해시 할 때에 대한 제공 이진 데이터는 16 진수 문자열로 표시됩니다. 해시 출력은 7f 이하의 16 진수 값에 대해서는 올바르지 만, 일단 8 비트 (> = 80)가되면 더 이상 올바른 답을 제공하지 않습니다. 문제를 찾을 수없는 것 같습니다. 여기 내 코드입니다 :
clear all
% add folder with class file to java path
functions_folder = strcat(pwd,filesep,'functions');
javaaddpath(functions_folder)
% data to hash in hex format
hex_string_in = '80';
hex_string_in_length = length(hex_string_in);
% split every to characters and calculate the data in each byte
for i=1:hex_string_in_length/2
data_uint8_array(1,i) = uint8(hex2dec(hex_string_in(2*i-1:2*i)));
end
% constructor
x = RIPEMD160;
% pass in binary data
x.update(data_uint8_array)
% get hash in binary format
hash_out_bin = x.digestBin();
% typecast binary data into unit8 primitive
hash_out_unit8=typecast(hash_out_bin,'uint8');
% convert to hex
hash_out_hex = dec2hex(hash_out_unit8)';
% pad with zeros if bytes all smaller than hex(80)
if(size(hash_out_hex,1))==1
hash_out_hex=[repmat('0',[1 size(hash_out_hex,2)]);hash_out_hex];
end
% final formatting, convert to lowercase
hash_out_hex = lower(hash_out_hex(:)')
가의 입력 것이
하지만, '80'은 대한 c8297aad716979548921b2e8e26ca8f20061dbef
의 올바른 해시를 생산하는 '7F'e633ca40d977e24a1ffd56b7a992e99b48d13359 대신감사 b436441e6bb882fe0a0fa0320cb2d97d96b4d1bc 정확한 결과를 제공합니다.
이것에 대한 진행 상황이 있습니까? 누락 된 부분을 나타내거나 대답을 수락하십시오. –