• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Generating an encrypted Key which will be around 32 characters

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 27368
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Straws are for suckers. Now suck on this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic