Generating an encrypted Key which will be around 32 characters
1 posts in topic
Flat View  Flat View

Posted By:   Ajay_Dalvi
Posted On:   Thursday, September 14, 2006 09:52 AM

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.



Re: Generating an encrypted Key which will be around 32 characters

Posted By:   murali_sappa  
Posted On:   Wednesday, September 20, 2006 12:45 AM

Try this -

MessageDigest digest = null;
digest = MessageDigest.getInstance("SHA-1");

byte[] encrypted = digest.digest();

This gives you 20 bytes

I use the following code to convert it into a 40 char hexadecimal string -

StringBuffer sb = new StringBuffer(encrypted.length * 2);
for ( int i = 0; i < encrypted.length; i++ )
int v = encrypted[i] & 0xff;
if ( v < 16 )
returnValue = sb.toString().toUpperCase();

Not efficient, but works.

About | Sitemap | Contact