Monday, March 11, 2013

MySql Encrypt and Decrypt Function

       Mysql supports many compression and encryption functions. One such technique is AES(Advanced Encryption Standard) algorithm. Using this, one can encrypt or decrypt the datas in table. General Syntax for Encrypt/Decrypt are
  
   AES_ENCRYPT(str,key_str)
   AES_DECRYPT(crypt_str,key_str)
 
      AES_ENCRYPT() encrypts a string and returns a binary string. AES_DECRYPT() decrypts the encrypted string and returns the original string. The input arguments may be any length and can contain alphanumeric characters. Basic Insert Query with and without Encrytion are as follows.
 
INSERT INTO `myTable`(myName,myPass) VALUES('Jimmy',AES_ENCRYPT('password1','key:test'));
INSERT INTO `myTable`(myName,myPass) VALUES('David','password2');
 
 
myName myPass
Jimmy ÙjˆçésŸ·
David password2
 
     To update plain text to Encrypted value, execute
 
UPDATE myTable SET myPass = AES_ENCRYPT('password2','key:test') WHERE myName='David';

myNamemyPass
David¦ã bf;× ÀäiO W

    For updating password column to encrypted value in an existing table you can either use the query directly as   

UPDATE myTable SET mypass = AES_ENCRYPT(mypass,'key:test');
 
  or can export data files alone and reinsert by using the below query.

 LOAD DATA INFILE 'C:/Sample.csv' INTO TABLE myTable(myname,@mypass) SET mypass=AES_ENCRYPT(@mypass,'key:test');
   
     Finally, to view the table datas, use decrypt query by passing the key value. Remeber that, if the given key value does not match with that of the key used while insertion, then it will return NULL value.
 
SELECT AES_DECRYPT(mypass,'key:test') FROM myTable;
myNamemyPass
Jimmypassword1
Davidpassword2

Friday, March 1, 2013

Displaying InfoWindow in Maps V3


      InfoWindows displays content in a floating window above the map. It has a content area and tapered stem, where the tip of the stem is at specified location of marker on the map. You can see the info window by clicking particular markers on Google map. To make the info window visible, you need to call the open() method, passing google maps and marker. If no marker is provided, then the info window will open at this position property. InfoWindow needs a Info Window options object, which specifies a set of initial parameters for displaying info window.
 
Sample Code for InfoWindow:

 InfoWindowOptions infoWindowOptions = InfoWindowOptions.create();
 infoWindowOptions.setContent(location);
 InfoWindow infoWindow = InfoWindow.create(infoWindowOptions);
 infoWindow.open(mapWidget, marker);

(For Creation of mapWidget and marker refer previous post).