Home > Article > Backend Development > java - How does PHP convert a string to a binary array, then perform md5 digest of the binary array, and convert the digested binary array into a hexadecimal string for output?
Convert the input parameter string waitForSignString into a binary array, and use UTF-8 for encoding (Java code such as: waitForSignString.getByte("utf-8")) to obtain the binary format data of the signature input parameter (waitForSignBytes).
Digest signature for waitForSignBytes using MD5, Sha1 or Sha256 algorithm. Get signature in result binary array data (signatureBytes)
Conduct hexadecimal string encoding on the resulting binary array (signatureBytes) of the signature output to obtain the final signature string (signature)
Algorithm expression:
String signature = Hex(digest (stringToSign+secretKey)) The digest algorithm can be: MD5, Sha256Hex
How should this signature algorithm be implemented in PHP? PHP's md5 seems to have no way to operate on arrays. . . .
Convert the input parameter string waitForSignString into a binary array, and use UTF-8 for encoding (Java code such as: waitForSignString.getByte("utf-8")) to obtain the binary format data of the signature input parameter (waitForSignBytes).
Digest signature for waitForSignBytes using MD5, Sha1 or Sha256 algorithm. Get signature in result binary array data (signatureBytes)
Conduct hexadecimal string encoding on the resulting binary array (signatureBytes) of the signature output to obtain the final signature string (signature)
Algorithm expression:
String signature = Hex(digest (stringToSign+secretKey)) The digest algorithm can be: MD5, Sha256Hex
How should this signature algorithm be implemented in PHP? PHP's md5 seems to have no way to operate on arrays. . . .
In PHP, strings are binary compatible and come with encoding by default. If your string itself is UTF-8 encoded, then it is already a UTF-8 binary array.
The md5 function in PHP can directly calculate the MD5 value of a string (that is, a binary array), and the default output is the result that has been converted to hexadecimal.
So, what the Modo operation is implemented in Java...
In PHP, it is $md5 = md5('string');