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

  • Home
  • SEARCH
  • 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 8336149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:53:46+00:00 2026-06-09T03:53:46+00:00

We have a python web service. It needs a hash as a parameter. The

  • 0

We have a python web service. It needs a hash as a parameter.
The hash in python is generated this way.

    hashed_data = hmac.new("ant", "bat", hashlib.sha1)
    print hashed_data.hexdigest()

Now, this is how I generate the hash from C#.

    ASCIIEncoding encoder = new ASCIIEncoding();
    Byte[] code = encoder.GetBytes("ant");
    HMACSHA1 hmSha1 = new HMACSHA1(code);
    Byte[] hashMe = encoder.GetBytes("bat");
    Byte[] hmBytes = hmSha1.ComputeHash(hashMe);
    Console.WriteLine(Convert.ToBase64String(hmBytes));

However, I’m coming out with different result.

Should I change the order of the hashing?

Thank you,

Jon

  • 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-09T03:53:47+00:00Added an answer on June 9, 2026 at 3:53 am

    In order to print the result:

    • In Python you use: .hexdigest()
    • In C# you use: Convert.ToBase64String

    Those 2 functions don’t do the same thing at all. Python’s hexdigest simply converts the byte array to a hex string whereas the C# method uses Base64 encoding to convert the byte array. So to get the same output simply define a function:

    public static string ToHexString(byte[] array)
    {
        StringBuilder hex = new StringBuilder(array.Length * 2);
        foreach (byte b in array)
        {
            hex.AppendFormat("{0:x2}", b);
        }
        return hex.ToString();
    }
    

    and then:

    ASCIIEncoding encoder = new ASCIIEncoding();
    Byte[] code = encoder.GetBytes("ant");
    HMACSHA1 hmSha1 = new HMACSHA1(code);
    Byte[] hashMe = encoder.GetBytes("bat");
    Byte[] hmBytes = hmSha1.ComputeHash(hashMe);
    Console.WriteLine(ToHexString(hmBytes));
    

    Now you will get the same output as in Python:

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

Sidebar

Related Questions

I have a python script that retrieves information from a web service and then
I have a web service to which users upload python scripts that are run
I'm new to Python and web development (although I have development experience with Client/Server
I have java sdk 1.7. I've always used django/python for web development, this will
I have been trying to create a web service out some python scripts, and
I have a python (django) web application. It uses an external web service (Facebook
Actually, i have started work on creating a web service in Python and C#(.NET
I have a Python 2.6 web app built on Pylons 0.9.7. The code in
I have the 'luck' of develop and enhance a legacy python web application for
I have a Python application in the bottle web-server that accesses a C shared-object

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.