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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:51:58+00:00 2026-05-25T21:51:58+00:00

This HMACSHA1 code below works for converting Password and Message to AFF791FA574D564C83F6456CC198CBD316949DC9 as evidence

  • 0

This HMACSHA1 code below works for converting “Password” and “Message” to AFF791FA574D564C83F6456CC198CBD316949DC9 as evidence by http://buchananweb.co.uk/security01.aspx.

My question is, Is it possible to have:

BYTE HMAC[] = {0x50,0x61,0x73,0x73,0x77,0x6F,0x72,0x64};
BYTE data2[] = {0x4D,0x65,0x73,0x73,0x61,0x67,0x65};

And still get the same value: AFF791FA574D564C83F6456CC198CBD316949DC9.

For example, if I was on a server and received the packet:

[HEADER] 08 50 61 73 73 77 6F 72 64 00
[HEADER] 07 4D 65 73 73 61 67 65 00

And I rip 50 61 73 73 77 6F 72 64 & 4D 65 73 73 61 67 65 from the packet and used this for my HMACSHA1. How would I go about doing that to get the correct HMACSHA1 value?

    BYTE HMAC[] = "Password";
    BYTE data2[] = "Message";
    //BYTE HMAC[] = {0x50,0x61,0x73,0x73,0x77,0x6F,0x72,0x64};
    //BYTE data2[] = {0x4D,0x65,0x73,0x73,0x61,0x67,0x65};
    HMAC_CTX ctx;
    result = (unsigned char*) malloc(sizeof(char) * result_len);
    ENGINE_load_builtin_engines();
    ENGINE_register_all_complete();
    HMAC_CTX_init(&ctx);
    HMAC_Init_ex(&ctx, HMAC, strlen((const char*)HMAC), EVP_sha1(), NULL);
    HMAC_Update(&ctx, data2, strlen((const char*)(data2)));
    HMAC_Final(&ctx, result, &result_len);
    HMAC_CTX_cleanup(&ctx);

    std::cout << "\n\n";


 for(int i=0;i<result_len;i++)
    std::cout << setfill('0') << setw(2) << hex << (int)result[i];

    int asd;
    std::cin >> asd;
// AFF791FA574D564C83F6456CC198CBD316949DC9

EDIT:

It works by doing this:

BYTE HMAC[] = {0x50,0x61,0x73,0x73,0x77,0x6F,0x72,0x64, 0x00};
BYTE data2[] = {0x4D,0x65,0x73,0x73,0x61,0x67,0x65, 0x00};

By adding 0x00, at the end. But, my question is more towards ripping it from data, and using it… would it still be fine?

  • 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-05-25T21:51:59+00:00Added an answer on May 25, 2026 at 9:51 pm

    The issue is the relation ship between arrays, strings, and the null char.

    When you declare “Password”, the compiler logically treats the string literal as a nine byte array, {0x50,0x61,0x73,0x73,0x77,0x6F,0x72,0x64, 0x00}. When you call strlen, it will count the number of bytes until it encounters the first 0x00. strlen(“Password”) will return 8 even though there are technically nine characters in the array of characters.

    So when you declare an array of 8 bytes as follows without a trailing null byte:

    BYTE HMAC[] = {0x50,0x61,0x73,0x73,0x77,0x6F,0x72,0x64};
    

    The problem is that “strlen(HMAC)” will count at least 8 bytes, and keep counting while traversing undefined memory until it finally (if ever) hits a byte that is zero. At best, you might get lucky because the stack memory always has a zero byte padding your array declaration. More likely it will return a value much larger than 8. Maybe it will crash.

    So when you parse the HMAC and MESSAGE field from your protocol packet, you count the number of bytes actually parsed (not including the terminating null). And pass that count into the hmac functions to indicate the size of your data.

    I don’t know your protocol code, but I hope you aren’t using strlen to parse the packet to figure out where the string inside the packet ends. A clever attacker could inject a packet with no null terminator and cause your code do bad things. I hope you are parsing securely and carefully. Typical protocol code doesn’t include the null terminating byte in the strings packed inside. Usually the “length” is encoded as an integer field followed by the string bytes. Makes it easier to parse and determine if the length would exceed the packet size read in.

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

Sidebar

Related Questions

I am using this class in MSVC++ 2010 Express: http://www.codeproject.com/KB/recipes/HMACSHA1class.aspx . I am running
This more of a style question, rather than a how to. So I've got
This code fails when I try to debug it using VC2010: char frd[32]=word-list.txt; FILE
This is an open-end interview question. Given an array with 2 numbers are duplicated
This is a C# code: byte[] pb = System.Text.Encoding.UTF8.GetBytes(policy.ToString()); // Encode those UTF-8 bytes
Why i got this error when i use following code? $customer_key = 'my_key'; $customer_securet
Look at the following line of java: Mac.getInstance(HmacSHA1); If I put this in a
I'm searching for a hmac-sha1 code sample in objective-c I saw this sample and
There is an example HMAC-SHA1 here that works in javascript http://jssha.sourceforge.net/ Text to encrypt
I have this problem, that usually api entry point works fine: https://www.google.com/analytics/feeds/accounts/default but when

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.