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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:16:33+00:00 2026-06-14T09:16:33+00:00

Our API platform using CMAC-AES hashes as the signature for a request. We have

  • 0

Our API platform using CMAC-AES hashes as the signature for a request. We have libraries available for creating this hash in Java and .NET but need to find a solution for PHP as well. Problem is I can’t find anything that seems to reliably generate a hash that matches the CMAC being generated on our server or via the Java/.NET library.

The only library I found is CryptLib, an alpha library.

https://github.com/ircmaxell/PHP-CryptLib

But it’s not generating the same hash and I’m not good enough with crypto to understand why (it’s forcing block sizes to 16 for AES, when what I find online says AES block size is 128).

Any other avenues I can go down?

  • 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-14T09:16:34+00:00Added an answer on June 14, 2026 at 9:16 am

    The PHP-CryptLib library above will, in the end, work just fine. My problem was just my own mistake related to binary vs. hex data.

    Using the test data provided by the library one

    require_once 'lib/CryptLib/bootstrap.php'; 
    
    $hasher = new CryptLib\MAC\Implementation\CMAC;
    
    $key = '2b7e151628aed2a6abf7158809cf4f3c'; // from test/Data/Vectors/cmac-aes ...
    $msg = '6bc1bee22e409f96e93d7e117393172a'; // from test/Data/Vectors/cmac-aes ...
    
    $cmac = $hasher->generate($msg,$key); 
    
    echo $cmac; 
    
    // $cmac should be 070a16b46b4d4144f79bdd9dd04a287c
    // actually getting ¢ nd{þ¯\ ¥á¼ÙWß­
    

    Except the CMAC hasher uses binary data not the ascii chars so one needs to pack it using pack():

    $key = pack("H*", '2b7e151628aed2a6abf7158809cf4f3c');
    $msg = pack("H*", '6bc1bee22e409f96e93d7e117393172a');
    

    My specific, real-world case was trying to hash an arbitrary string, such as:

    $msg = 'Client|Guid-023-23023-23|Guid-0230-2402-252|string|123456|2012-11-08T20:55:34Z';
    

    And to do that I needed a function like this:

    function pack_str($str) {        
        $out_str = ""; 
        $len = strlen($str); 
        for($i=0; $i<$len; $i++) { 
            $out_str .= pack("c", ord(substr($str, $i, 1))); 
        } 
        return $out_str; 
    } 
    

    Once the data was packed with that function and run through the hasher, I got the CMAC hash I was expecting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Google Apps Provisioning API to synchronize user data with our internal
What are some good authoring tools for creating cross-platform help files for end-users? (Our
I am looking at implementing a Web Service API for our product. I have
My team and I have found that documenting our project (a development platform w/
I have a WCF API which supports SOAP/JSON/XML but we don't provide JSONP. This
We are creating a web api application. In one of our API's if there
We have a new feature in our API that is used by internal developers
I have been removing our website from wordpress onto its own platform. Temporarily I
In our API library, we have a number of classes that implement a method
We have an existing API where a client asks our server for information that

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.