Welcome to my blog, hope you enjoy reading
RSS

Friday 9 November 2012

How Encrypt the GWT String from Client Side


  • Download the jar file from link.
  • Add the following in the .gwt.xml file 

  •         <inherits name='com.googlecode.gwt.crypto.Crypto'/>

     
  • Use the following code in the class

                  String getSHA1for(String text) 
               {
 SHA1Digest sd = new SHA1Digest();
 byte[] bs = text.getBytes();
 sd.update(bs, 0, bs.length);
 byte[] result = new byte[20];
 sd.doFinal(result, 0);
 return byteArrayToHexString(result);
}

String byteArrayToHexString(final byte[] b) 
               {
 final StringBuffer sb = new StringBuffer(b.length * 2);
 for (int i = 0, len = b.length; i < len; i++) {
   int v = b[i] & 0xff;
   if (v < 16) sb.append('0');
   sb.append(Integer.toHexString(v));
 }
 return sb.toString().toUpperCase();
}

0 comments: