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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:48:03+00:00 2026-05-14T07:48:03+00:00

In an app we are calculating a SHA1Hmac in java using the following: SecretKey

  • 0

In an app we are calculating a SHA1Hmac in java using the following:

SecretKey key = new SecretKeySpec(secret, "HmacSHA1");
Mac m = Mac.getInstance("HmacSHA1");
m.init(key);
byte[] hmac = m.doFinal(data);

And later, the hmac is verified in C# – on a SmartCard – using:

  HMACSHA1 hmacSha = new HMACSHA1(secret);
  hmacSha.Initialize();
  byte[] hmac = hmacSha.ComputeHash(data);

However, the result is not the same. Did I overlook something important?

The inputs seem to be the same. Here some sample inputs:

Data: 546573746461746131323341fa3c35
Key: 6d795472616e73616374696f6e536563726574

Result Java: 37dbde318b5e88acbd846775e38b08fe4d15dac6
Result C#:   dd626b0be6ae78b09352a0e39f4d0e30bb3f8eb9

I wouldn’t mind to implement my own hmacsha1 on both platforms, but using what already exists….

Thanks!

  • 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-14T07:48:04+00:00Added an answer on May 14, 2026 at 7:48 am

    With this Java code:

    static byte[] doHMAC(byte[] data, byte[] secret)
    {
        SecretKey key = new SecretKeySpec(secret, "HmacSHA1");
        Mac m = Mac.getInstance("HmacSHA1");
        m.init(key);
        return m.doFinal(data);
    }
    

    then I get the dd626b0be6ae78b09352a0e39f4d0e30bb3f8eb9 which is what you have from your C# implementation. Also, I have verified that value with regards to my own HMAC and SHA-1 implementation (in Java) and I also get that result.

    It seems that your Java code is flawed, but not in the part you show (except your m.init(secret) which does not compile — it has to be m.init(key)). As my code shows, the Java implementation of HMAC/SHA-1 is correct and you invoke it properly. My guess is that you are not inputting the right data or key.

    (I am using Sun’s JDK 1.6.0_16)

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

Sidebar

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.