java-php How to MD5 a binary array after a string to a binary array and convert the binary array after the digest to a hexadecimal string output?

Source: Internet
Author: User
Tags sha1 sha256 algorithm
Convert the input parameter string waitforsignstring to a binary array, encoded with UTF-8 (Java code such as: Waitforsignstring.getbyte ("Utf-8")), The binary Format data (waitforsignbytes) that is signed into the parameter is obtained.

The Waitforsignbytes is digest signed using the MD5,SHA1 or Sha256 algorithm. Get signed in result binary array data (signaturebytes)

A 16-character string encoding of the result binary array (signaturebytes) of the signature output, resulting in a final signature string (signature)

Algorithm expression:

String signature = Hex (Digest (Stringtosign+secretkey)) where the digest algorithm can be: MD5, Sha256hex

How should this signature algorithm be implemented in PHP? PHP MD5 does not seem to be able to manipulate arrays ....

Reply content:

Convert the input parameter string waitforsignstring to a binary array, encoded with UTF-8 (Java code such as: Waitforsignstring.getbyte ("Utf-8")), The binary Format data (waitforsignbytes) that is signed into the parameter is obtained.

The Waitforsignbytes is digest signed using the MD5,SHA1 or Sha256 algorithm. Get signed in result binary array data (signaturebytes)

A 16-character string encoding of the result binary array (signaturebytes) of the signature output, resulting in a final signature string (signature)

Algorithm expression:

String signature = Hex (Digest (Stringtosign+secretkey)) where the digest algorithm can be: MD5, Sha256hex

How should this signature algorithm be implemented in PHP? PHP MD5 does not seem to be able to manipulate arrays ....

    1. In PHP, strings are binary compatible and are encoded by default, and if your string itself is UTF-8 encoded, it is already a UTF-8 binary array.

    2. 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 16 binary.

So, in Java, what you want to do is to implement ...
In PHP, it is$md5 = md5('字符串');

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.