2

I have try to generate unlock key like XXXX-XXXX-XXXX or simply small length string or Hexstring. I am using RSA algorithm to encrypt and decrypt the Key. I got some long string like

Q65g2+uiytyEUW5SFsiI/c5z9NSxyuU2CM1SEly6cAVv9PdTpH81XaWS8lITcaTZ4IjdmINwhHBosvt5kdg==

when I convert the byte array (array size is 64 byte) using the below convert method.

Convert.ToBase64String(bytes); 

My requirement is to generate the minimal length Key. Is there any way to convert the Byte array (array size is 64 byte) to minimal length and I need that back to byte array or any other suggestions (to minimize the string length) would be helpful.

I have tried to convert the output string to Hex decimal, but the output is too long than the string.

Vinoth
  • 1,975
  • 21
  • 34
  • 1
    What are your requirement on the alphabet? Why converting it to base 64? you need to store it somewhere, to send it through network ? base64 strings are bigger than base 256 strings... – Kek Aug 08 '12 at 09:39
  • take a look at hashing algorithms: SHA-1, MD5... – oleksii Aug 08 '12 at 09:43
  • @Kek, We will provide this Key to customer to install our product. We will convert the string into byte array and unlock the features in WIX installer based on the byte array. – Vinoth Aug 08 '12 at 09:50
  • 1
    oleksii - Hashing wont work, since the OP wants to be able to convert string back to byte array. – logicnp Aug 08 '12 at 09:56

3 Answers3

1

You may want to take a look at What is the most efficient way to encode an arbitrary GUID into readable ASCII (33-127)? There the Base 85 encoding is discussed which is used to compress PDF files.

Though, the difference between Base64 and Base85 in your case is 8 characters.

You can safely remove trailing '==' in Base64 string because it is used for alignment and will always be there for 64-byte values (Of course you will have to add these characters back to decode the string).

Community
  • 1
  • 1
Artemix
  • 2,113
  • 2
  • 23
  • 34
0

Since you mention you want users to be able to type in the string, there will be an inverse correlation between easy-of-use from point of view of users and the length of string.

Even typing a Base64 string is prone to lot of errors. Base32 strings are much easier to type, but correspondingly the length will increase.

If the users can Copy-Paste the key, then the above is moot and there should not be any valid reason why the length of the string should be as small as possible.

logicnp
  • 5,796
  • 1
  • 28
  • 32
0

Obviously, you can only fit a certain amount of data into a fixed number of characters. You have pretty much maxed out the limit with base64 already which gives you 6 bits per byte.

Therefore you need to reduce the amount of data that needs to be stored. Can you reduce the key length? You could use a 96 bit key (by always leaving all other bytes zero). That would require 16 base64 characters which is much better.

It seems you don't need much security against brute forcing. So you can reduce the key size even further.

usr
  • 168,620
  • 35
  • 240
  • 369