Convert MD5 messageDigest from Java to Digest::MD5 Ruby -


i want use digest::md5 on ruby java code. java code:

public static string md5encode(string input, string salt) {         try {             messagedigest messagedigest = messagedigest.getinstance("md5");             byte[] hash = null;              try {                 messagedigest.update(salt.getbytes("utf-8"));                 messagedigest.update(input.getbytes("utf-8"));                 hash = messagedigest.digest();             } catch (unsupportedencodingexception exception) {                 logger.error("md5encoder:encode:" + exception.tostring());             }              if (hash != null) {                 stringbuilder output = new stringbuilder(2 * hash.length);                  (byte b : hash) {                     output.append(string.format("%02x", b & 0xff));                 }                  return output.tostring();             }         } catch (nosuchalgorithmexception exception) {             logger.error("md5encoder:encode:" + exception.tostring());         }          return null;     } 

and ruby code, result not right: (the input variable in java password variable on ruby, , salt variable same on both)

 salt = securerandom.hex   if (params[:gamestate_password] != "")     password = digest::md5.hexdigest(params[:gamestate_password] + salt)     user_query = "update user_v54 set password= '#{password}', passwordsalt= '#{salt}' userid='#{params[:userid]}'"   end 

you should put salt in ruby same order in java (in front of password):

password = digest::md5.hexdigest(salt + params[:gamestate_password]) 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

delphi - Indy UDP Read Contents of Adata -