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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:26:52+00:00 2026-05-15T11:26:52+00:00

I was looking for extension methods and stumbled in to a function that claims

  • 0

I was looking for extension methods and stumbled in to a function that claims to mimic how PHP does the MD5 functions. Here’s an exact copy(I don’t get why the declaration and initialization of the Crypto were done separately…)

public static string MD5(this string s) {
    MD5CryptoServiceProvider provider;
    provider = new MD5CryptoServiceProvider();
    byte[] bytes = Encoding.UTF8.GetBytes(s);
    StringBuilder builder = new StringBuilder();

    bytes = provider.ComputeHash(bytes);

    foreach(byte b in bytes) {
        builder.Append(b.ToString("x2").ToLower());
    }

    return builder.ToString();
}

The MSDN library shows this as being the way to do it:

byte[] MD5hash (byte[] data) {
   // This is one implementation of the abstract class MD5.
   MD5 md5 = new MD5CryptoServiceProvider();

   byte[] result = md5.ComputeHash(data);

   return result;
}

Except for the argument being a string, what’s the need for the stringbuilder and appending each byte? If I just do Encoding.UTF8.GetBytes on the string, I should have a byte array, usable for the method found in the MSDN library.

Can anyone point to a use for the extension method?

  • 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-15T11:26:52+00:00Added an answer on May 15, 2026 at 11:26 am

    The first method returns the hexadecimal encoding of the result. The latter returns it has a byte[] without encoding it as hex in a string.

    The former is more of a convenience method when returning the result as a string (perhaps in a URL, form, etc).

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

Sidebar

Related Questions

I'm looking for a PHP extension that allows me to connect, bind/listen, send, and
Looking for a Linux application (or Firefox extension) that will allow me to scrape
I am looking for either a FireFox extension, or a similar program, that allows
I am looking into strong typed Windows Forms databinding using extension methods. I have
Looking for an example that: Launches an EXE Waits for the EXE to finish.
I am looking for how the methods like ArrayList#sort(Closure) are implemented in Groovy. I've
With .NET 3.5 a large amount of extension methods were added to the core
By default Visual Studio displays all members and its extension methods for a type
While looking at this question and it's answers I thought that it would be
I'm looking to write a library that uses the new optional parameters feature of

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.