PHP's DES CBC message authentication method

Source: Internet
Author: User
MAC DEC CBC

Recently there is a project that sends messages using the MAC (message authentication Code), using the DES CBC algorithm.
Online check, probably meaning is to give the data to calculate a check code, with the data itself sent out, the end of the verification code to confirm whether the data has been tampered with.

Want to ask, PHP has no function can directly implement this function, their own writing function is segmented, is different or, is also the encryption of the head is big. I think there is mcrypt_cbc such a function, do not know whether there is any relationship.

Please help the master! It would be better to give an example to illustrate, or to point to a direction.


Reply to discussion (solution)

Mcrypt_cbc

Use CBC to add/decrypt data.

Syntax: string MCRYPT_CBC (int cipher, string key, string data, int mode, string [IV]);

return value: String

Function type: Encoding processing

Content Description

This function uses CBC password retrieval (cipher block chaining) to encrypt and decrypt the data. The parameter cipher is an Add/decrypt method, such as Mcrypt_tripledes. Parameter key is the password key, of course, it should be careful to maintain its confidentiality. The string to encrypt or decrypt is placed in the parameter data. The parameter mode means encrypting the Mcrypt_encrypt or decrypting the mcrypt_decrypt. The parameter IV is an omitted parameter that represents the vector initialization (initialization vector, IV).

Forgive me for copying the official instructions, but purely from the interpretation, this is a cryptographic function. According to your needs, although you can generate a ciphertext, and then the key also sent over, to the end of the sent over the plaintext with the same key again encrypted, compared ciphertext, it is possible to achieve the purpose of verification. However, the key transmission loses its security. Relatively simple, MD5 seems to be much easier. Because no key is required.

  • 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.