MACTripleDES in PHP

I am trying to get the equivalent of a C Triple Class MAC TripleDES MACTripleDES.

I tried following mcrypt(), but it's just an encoding in TripleDES. I need to get the equivalent MACTripleDES string as the one generated in C # to authenticate the message.

I also looked at the PHP function hash_hmac(), but it does not make it possible to generate MAC using TripleDES

+5
source share
2 answers

I'm not sure, since Microsoft did not bother to say which standard corresponds to their class, but I suspect that this NIST document that the Microsoft class computes using only triple DES instead of DES.

, , mcrypt.

1:

, , PHP #.

-, #:

using System;
using System.Text;
using System.Security.Cryptography;

namespace TDESMacExample
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            var keyString = "012345678901234567890123";
            var keyBytes = Encoding.ASCII.GetBytes(keyString);
            var mac = new MACTripleDES(keyBytes);
            var data = "please authenticate me example number one oh one point seven niner";
            Console.WriteLine(data.Length);
            var macResult = mac.ComputeHash(Encoding.ASCII.GetBytes(data));
            Console.WriteLine(BitConverter.ToString(macResult));
            // B1-29-14-74-EA-E2-74-2D
        }
    }
}

, PHP:

    <?php
    $data = 'please authenticate me example number one oh one point seven niner';
    $key = '012345678901234567890123'; // Key must be 24 bytes long
    $iv = '\x00\x00\x00\x00\x00\x00\x00\x00'; // All zero IV is required

    $cipher = mcrypt_cbc(MCRYPT_3DES, $key, $data, MCRYPT_ENCRYPT, $iv);
    $mac_result = substr($cipher, -8); // Last 8 bytes of the cipher are the MAC

    echo "mac result : " . bin2hex($mac_result);
    echo "<br>";
    ?>
+7

MAC - , CBC. , IV , .

MAC . F FIPS-81, DES .

+1

All Articles