Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

unique key generator

Posted on 2007-03-26
6
Medium Priority
?
1,187 Views
Last Modified: 2013-12-17
Hi i want to generate a unique key.
I want it to be made up of letters and numbers.

I have been looking at RC2 using the following code:

-----------------------------------
using System.Security.Cryptography;

static void Main(string[] args)
{
RC2 r = RC2.Create();
r.GenerateIV();
r.GenerateKey();

for (short i = 13; i < 200; i += 13)
{
byte[] data = BitConverter.GetBytes(i);
byte[] enc = r.CreateEncryptor().TransformFinalBlock(data, 0, 2);
Console.WriteLine("{0}\t= {1}", 13, Convert.ToBase64String(enc));
}
Console.ReadLine();
}

---------------------------------------------

The problem is that this generates a key that contains non alphanumeric characters:
i.e
/MQpLW6J+3o=  

----------------------------

so is there anything out there that will generate a unique alphanumeric key (Not a guid) about 10-12 characters.  something that will be unique across time.

thanks very much.
0
Comment
Question by:MrKevorkian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18793961
What's wrong with a GUID?...you could just remove the hypens and use Substring() to get the required number of characters from the left, middle, or right side...
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 18798505
if i remove characters - whats the guarentee that it will be unique?
0
 
LVL 1

Author Comment

by:MrKevorkian
ID: 18798529
i have had a look at RNGCryptoServiceProvider and that seems that it might be useful.  But doesnt  allow you to introduce a seed to it initially.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 800 total points
ID: 18800168
If you want to GUARANTEE that your number is unique then you would have to store every single number you've ever used in a database so you can search for previously used values.

Otherwise I'm pretty sure it doesn't matter what system you use to generate your "unique" key as you are at best simply "not likely" to get a repeat value.

But I'm no security expert...
0
 
LVL 11

Accepted Solution

by:
rdrunner earned 1200 total points
ID: 18814269
Hello...

Du you want to include any other informations in your "key" or should it "just" be a number?

What you could do is to create a small function that will convert several bytes into a set of allowed characters.  This could be done along the lines of mime encoding. So basically you get your number as a byte array, then you take small chunks of it (in32 Values) and mod them through the number of allowed characters (This gets the remainder) and pick the nth Character out of your allowed set.. then you (Integer) divide them through the number of allowed chars and repeat the process until you are left with a '0'

To revert you can reverse the process and retrieve the number again.

Also this allows you to decide which letters are skipped (for example I/1 or O/0), so there wont be any characters that are hard to read...
0
 
LVL 11

Expert Comment

by:rdrunner
ID: 18814296
Edit:
To achieve uniqueness, i would just store the numbers in the DB like suggested or use a (counter * key + counter) that will allways reach the desiered target-Number length. (e.g. if you know you need to generate "millions" then dont start the counter at "1" but use 1000000 as start for your counter.

The merging of those numbers could be more complex, depending on your need for this key.... But it will allow a unique number with each counter value, and it can be reproduced which counter was used to generate the key...
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question