• Post Reply Bookmark Topic Watch Topic
  • New Topic

Generating an encrypted Key which will be around 32 characters  RSS feed

 
Ajay Dalvi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a String which is a combination of 8 different fields. Length of the String is around 100 characters. I have to generate an encrypted key of around 32 characters from this String. Can anyone please suggest how to do this.
I have tried the DES algorithm and javax.crypto.Cipher class and sun.misc.BASE64Encoder class.
Using this it is generating Encrypted String around 130 characters.

Can anyone suggest me how to achieve the Encrypted key having length around 32 characters.

Thanks,

-Ajay
 
Henry Wong
author
Sheriff
Posts: 23292
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you may be mixing terms here... the DES encryption key is 8 bytes long. It doesn't depend on the data that is being encrypted.

If you are talking about the encypted text that is returned, you are pretty much stuck. Both encryption and base64 should make text larger, you can't encrypt and base 64 a string and expect it to be smaller. (particularly going from 100 bytes to 32 bytes)

Henry
 
Paul Clapham
Sheriff
Posts: 22713
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the other hand if your requirement is actually hashing -- i.e. you can produce a smaller unreadable version of the key but you have no way of getting the original key back from that -- then there are plenty of ways to do that. I use the java.security.MessageDigest class but I'm sure there are other possibilities.
 
Ajay Dalvi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Henry and Paul.
Sorry for mixing terms related to encrypted key and encrypted text.
Actually I have to create encrypted text (which will be around 32 characters) from a String (which will be having around 100 characters).
Henry, you have mentioned that we can not make encypted text smaller.
My Requirement is, I need to generate one String which will be combination of some fields. I need to encrypt that and this encrypted text will be used as sort of License Key while installing some application. Since the Encrypted text will be acted as sort of License Key, I have to generate that Encrypted Text having length around 32 characters...
Can you suggest me something regarding this...

Thanks alot for your help

-Ajay
 
Tim LeMaster
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets talk more specific. I'm going to call these fields userName and productName.

With encryption you could take the cipher text containing userName and productName and get them back using a cipher key. However if you have a 100 bytes you aren't going to encrypt it and wind up with <100 bytes.

Now you could create a one-way-hash of these fields. You would not be able to recover them. However given the fields you would be able to recreate the hash and make sure they match.

MD5 - is such a hashing algorithm - but it definately has weaknesses. It can however be represented by 32 hexidecimal digits.

I hope this helps, but if you want to do this right, please take the time to study this topic in depth.

Oh and please pass the salt.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!