Posts

Get UnixTimeStamp in Java

Current UnixTimeStamp: long currentUnixTimestamp = System.currentTimeMillis()/1000; In  MYSQL:  1) From date to UnixTimestamp:  SELECT UNIX_TIMESTAMP('2012-12-27 08:03:00'); 2) From UnixTimeStamp to date:  SELECT FROM_UNIXTIME(1356618379);

Auto scroll to a DIV on page

You can set your page focus to a DIV on the basis of id element. Let's say you have an element...          <div id="my_div" >  Scroll here.... </div> Always Use: document.getElementById('my_div').scrollIntoView();

Ajax request using jquery

$.ajax({       type : "POST ",       url : "/login" ,       cache: false,       data : {userId: 'test-user' , timestamp: '20121119' },       dataType: 'json' ,       success: function (data) {               $.each(data, function(index, element) {                    alert(index+" and "+element);           });               },       error: function(jqXHR, exception) {            if (jqXHR.status === 0) {                alert('Not connect.\n Verify Network.');            } else if (jqXHR.status == 404) {                alert('Requested page not fo...

Calculate Time difference in Java

public static long checkTimeDifference(String time1,String time2){                //time1 and time 2 must be in HH:mm:ss format     SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");     Date date1;     Date date2;     long difference=0; try { date1 = format.parse(time1); date2 = format.parse(time2); difference = date2.getTime() - date1.getTime(); } catch (ParseException e) { e.printStackTrace(); } return difference;         }

java.security.InvalidKeyException: Illegal key size or default parameters

java.security.InvalidKeyException: Illegal key size or default parameters Caused by: java.security.InvalidKeyException: Illegal key size or default parameters     at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]     at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]     at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]     at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]     at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6] -------------------------------------------------------------------------------------- There are key size restrictions with the default crypto files local_policy.jar and US_export_policy.jar comes with JDK – which limits it to 128. If the security policy you are using has a key size larger than this limit– then the above exception is thrown. Please follow these instructions... You need to patch your JDK with Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files. For JDK1.5 vis...

Double encryption decryption (Blowfish+Base64) in java

Double Encryption and decryption using Blowfish and Base64 -------------------------------------------------------------- import java.security.NoSuchAlgorithmException; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class BlowfishCipher {  public static void main(String[] args) throws Exception {    KeyGenerator keygenerator = KeyGenerator.getInstance("Blowfish");       SecretKey secretkey = keygenerator.generateKey();        Cipher cipher = Cipher.getInstance("Blowfish");    // get the text to encrypt    String inputText = "User_ID=Test12&User_Timestamp=20121030040002";    System.out.println("Double Encryption..................for :"+inputText);    cipher.init(Ciph...

Blowfish encryption decryption in Java

Blowfish Encryption Decryption using KeyGenerator ---------------------------------------------- import java.security.NoSuchAlgorithmException; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class BlowfishCipherExample {  public static void main(String[] args) throws Exception {    // create a key generator based upon the Blowfish cipher    KeyGenerator keygenerator = KeyGenerator.getInstance("Blowfish");    // create a secret key    SecretKey secretkey = keygenerator.generateKey();    // create a cipher based upon Blowfish    Cipher cipher = Cipher.getInstance("Blowfish");    // initialise cipher to with secret key      cipher.init(Cipher.ENCRYPT_MODE, secretkey); ...