Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8542721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:08:05+00:00 2026-06-11T12:08:05+00:00

There are great posts on how to use JAVA to create a MYSQL MD5

  • 0

There are great posts on how to use JAVA to create a MYSQL MD5 hash, however is it possible to go the other way – use SQL to produce what java does ?

in SQL:

Select MD5('secret') = 5ebe2294ecd0e0f08eab7690d2a6ee69

in Java, the MD5 algo yields: 94-6634-108-20-48-32-16-114-85118-112-46-90-18105

First off I can see the Java one is a decimal representation, so pairing off the SQL output and converting to DECIMAL gives: 9419034148236208224240142171118144210166238105

The only part that’s the same is the Front 2 and last 4.

Anyone have ideas on how to use SQL to generate what Java would produce?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:08:06+00:00Added an answer on June 11, 2026 at 12:08 pm

    I don’t have this fully worked out, but hopefully, these hints will help:

    In Java, if you take the direct result of the md.digest() call, you have a byte array.
    Instead of converting that to a String representation, just output the bytes as Integers.
    You’ll see that they are:

    94
    -66
    34
    -108
    -20
    -48
    -32
    -16
    -114
    -85
    118
    -112
    -46
    -90
    -18
    105

    So, the dashes in the resulting string conversion aren’t separators, they are arithmetic signs.
    The java hash is a simple concatenation of the byte values as (signed) ints.

    When you Select MD5(‘secret’), you getting a string of 32 hex digits.
    I verified that if in Java, you convert each byte to it’s hex representation, and concatenate them, you get the same string that MySQL returns.

    So, it seems to me that what you would need to do in MySQL is to iterate the result of Hex(), one hex char at a time (perhaps using SUBSTRING()), convert each to decimal, and concatenate them.

    Edit – looks like you are almost doing it correctly, but you need to convert each pair of hex digits to Byte instead of int, so for example, ‘0xbe’ is -66, not 190

    Edit #2 – I was intrigued by how relatively difficult this is to do in MySQL, so I persisted (joke intended). The following stored function seems to do the job:

    drop function if exists java_md5;
    delimiter |
    create function java_md5(secret VARCHAR(255)) 
      RETURNS VARCHAR(255) 
      DETERMINISTIC 
      BEGIN
        DECLARE result varchar(255);
        DECLARE md5String char(255);
        DECLARE pair char(2);
        DECLARE pairInt int;
        DECLARE idx int;
        set md5String = MD5(secret);
    
        set result = '';
        set idx = 1;
        WHILE(idx < 32) DO
          set pair = substring(md5String, idx, 2);
          set pairInt = ascii(unhex(pair));
          set pairInt = if(pairInt > 127, pairInt - 256, pairInt);
          set result = concat(result, pairInt);
          set idx = idx + 2;
        END WHILE;
        RETURN result; 
      END|
    delimiter ;
    
    select java_md5('secret');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I use mysql and phpMyAdmin, I was wondering if there is as great
Is there any great tutorial out there on how to create rain in GLSL
Is there a way that I can remove links in posts via my functions.php
i know nothing about medical records but im sure there's great opportunity in it
WPF is great because there are many ways to achieve your goals. For example,
. Hello, I'm using jqueryui's datepicker, and it works great but there's a problem.
There are a lot of great open-source projects on github. Most of them come
While there are a handful of great programs for ISV Startups (BizSpark, Emplower ISV,
WiX is great in that there is no GUI, you just write the installer
Reflection API is great thing out there to manipulate the OOP stuff and looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.