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 8900703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:09:45+00:00 2026-06-15T01:09:45+00:00

VB Code that works: Public Function Encrypt(ByVal Data As String) As Byte() Dim md5Hasher

  • 0

VB Code that works:

Public Function Encrypt(ByVal Data As String) As Byte()
    Dim md5Hasher As New MD5CryptoServiceProvider()
    Dim hashedBytes As Byte()
    Dim encoder As New UTF8Encoding()

    hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(Data))
    Return hashedBytes
End Function

JAVA code that works:

byte[] bytes = stringToConvert.getBytes("UTF-8");
MessageDigest m = MessageDigest.getInstance("MD5");
hashedBytes = m.digest(bytes);

What I have tried in PHP that does not work and I think I know why.

I think it is because of this:

Characters in Java are stored as Unicode 16-bit sequences. In PHP they’re single byte sequences.
This is the code I have tried…

     $UTFbString = UTF8_encode($bString);
     $hashedBytes = md5($UTFbString, true);

Ok, I have found that if I use this method…

 function ascii_to_dec($str)
 {
     for ($i = 0, $j = strlen($str); $i < $j; $i++) {
     $dec_array[] = ord($str{$i});
  }
   return $dec_array;
  }

and this code…

 $bStringArr = array( ascii_to_dec($bString));

 I can get back an array that matches the byte array in JAVA.

 So the next challenge is to convert that to bytes then md5 hash those bytes?

The JAVA code that does that looks like this…

   MessageDigest digester = MessageDigest.getInstance("MD5");
   byte[] bytes = new byte[8192];
   int byteCount;
   while ((byteCount = in.read(bytes)) > 0) {
      digester.update(bytes, 0, byteCount);
   }
   byte[] digest = digester.digest();

Any suggestions on implementing something something like this in PHP?

  • 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-15T01:09:46+00:00Added an answer on June 15, 2026 at 1:09 am

    Although I am not sure why one would want to use a byte array as md5 hash, here is my solution:

    <?php
        $stringToConvert = "äöüß";
        $md5 = md5(utf8_encode($stringToConvert), true);
        for($i = 0; $i < strlen($md5); $i++) {
            $c = ord($md5[$i]);
            $b[] = $c > 127 ? $c-256 : $c;
        }
        print_r($b);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a code excerpt from AspComet project that works with Autofac. public MessageBus(IClientRepository
Public Function Foo() as String() Dim bar As String = {bar1,bar2,bar3} Return bar End
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
Considering that simple java code which would not work: public class Bar extends AbstractBar{
I'm testing my code that works with dynamic tables in Firefox. The tables I
I have the following code that works fine up to the last line in
I have the following code that works great for row click, but I want
I have the following code that works without using throw however when I use
this is the curl code that works in command line : $ curl -F
I have this code that works in a unit test but doesn't work when

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.