Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Unique integer from string?

Unique integer from string?

Scheduled Pinned Locked Moved C#
comcryptographyquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nathan Ridley
    wrote on last edited by
    #1

    Is it possible to generate a unique number from a string of say 50-100 characters? Is that what a "hash" is? If so, how do you do it? NATHAN RIDLEY Web Application Developer email: nathan @ netlab.com.au [remove the spaces before and after the @ symbol]

    A H J 3 Replies Last reply
    0
    • N Nathan Ridley

      Is it possible to generate a unique number from a string of say 50-100 characters? Is that what a "hash" is? If so, how do you do it? NATHAN RIDLEY Web Application Developer email: nathan @ netlab.com.au [remove the spaces before and after the @ symbol]

      A Offline
      A Offline
      amatyasik
      wrote on last edited by
      #2

      Hello! I'm not a guru but i think MD5 encryption is a solution for this case Bye

      1 Reply Last reply
      0
      • N Nathan Ridley

        Is it possible to generate a unique number from a string of say 50-100 characters? Is that what a "hash" is? If so, how do you do it? NATHAN RIDLEY Web Application Developer email: nathan @ netlab.com.au [remove the spaces before and after the @ symbol]

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        While it's not guaranteed to be unique, it is mathematically impropable (not impossible) to get the same hash. You can generate a digest over your string like so:

        public string Digest(string value)
        {
        if (value == null) throw new ArgumentNullException("value");
        byte[] buffer = Encoding.Unicode.GetBytes(value); // Or whatever encoding
        MD5 md5 = MD5.Create();
        byte[] hash = md5.ComputeHash(buffer);
        return ConvertToHex(hash);
        }
        public string ConvertToHex(byte[] buffer)
        {
        if (buffer == null) throw new ArgumentNullException();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < buffer.Length; i++)
        sb.AppendFormat("{0:X2}", buffer[i]);
        return sb.ToString();
        }

        Microsoft MVP, Visual C# My Articles

        1 Reply Last reply
        0
        • N Nathan Ridley

          Is it possible to generate a unique number from a string of say 50-100 characters? Is that what a "hash" is? If so, how do you do it? NATHAN RIDLEY Web Application Developer email: nathan @ netlab.com.au [remove the spaces before and after the @ symbol]

          J Offline
          J Offline
          Jeff Varszegi
          wrote on last edited by
          #4

          Hash function definition When people talk about hashing data, they're passing it through a hash function. Hash functions are one-way functions at least in the sense that data over an unconstrained range may be made to fit into a constrained range; however, it's sometimes possible to figure out possible input values from some output. MD5 is an often-used hashing algorithm. The single most popular use for hashing, in my experience, is to store passwords in a somewhat secure way. Many servers don't store a plain-text version of a password, or can be configured that way; instead, they store the hashed version, and when some client requests authentication, they take the passed password, hash it, and compare it to the hashed version. Regards, Jeff Varszegi EEEP!

          N 1 Reply Last reply
          0
          • J Jeff Varszegi

            Hash function definition When people talk about hashing data, they're passing it through a hash function. Hash functions are one-way functions at least in the sense that data over an unconstrained range may be made to fit into a constrained range; however, it's sometimes possible to figure out possible input values from some output. MD5 is an often-used hashing algorithm. The single most popular use for hashing, in my experience, is to store passwords in a somewhat secure way. Many servers don't store a plain-text version of a password, or can be configured that way; instead, they store the hashed version, and when some client requests authentication, they take the passed password, hash it, and compare it to the hashed version. Regards, Jeff Varszegi EEEP!

            N Offline
            N Offline
            Nathan Ridley
            wrote on last edited by
            #5

            Thanks guys for the answers. Very helpful! :) NATHAN RIDLEY Web Application Developer email: nathan @ netlab.com.au [remove the spaces before and after the @ symbol]

            J 1 Reply Last reply
            0
            • N Nathan Ridley

              Thanks guys for the answers. Very helpful! :) NATHAN RIDLEY Web Application Developer email: nathan @ netlab.com.au [remove the spaces before and after the @ symbol]

              J Offline
              J Offline
              Jeff Varszegi
              wrote on last edited by
              #6

              You're welcome! Regards, Jeff Varszegi EEEP!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups