Thursday, August 11, 2011

View Linux version using command

Use following command to get linux version.

uname -a

Monday, August 8, 2011

Mysql set auto increment start value

In default, auto increment values are started in 0(zero). Suppose you, want to start value auto increment with 1234, use the following command after table creation.

ALTER TABLE TableName AUTO_INCREMENT=1234

Wednesday, July 20, 2011

Get last bash command in shell

Suppose you want to get previously used command without using up / down arrows,

Simply type !(command start char).

Example :-

If you want to get "ps -eaf|grep java", simply type !p in the bash shell.

NOTE :- This will return last executed command.

RSA java encrypt, decrypt

Following code can be used to encrypt, decrypt string using RSA encryption.

NOTE :- Apache Commons Codec used for encode string to base64.

import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;

import javax.crypto.Cipher;
import org.apache.commons.codec.binary.Base64;

public class MainClass {

    public static void main(String[] args) throws Exception {
        byte[] expBytes = Base64.decodeBase64("AQAB");
        byte[] modBytes = Base64.decodeBase64("nzLiZDSiu484r5NcBQN3rNP3x5aqY3Eq6CkQDwuilTzd5ZNdTcTxw7C1JQ9ih27Vq4RU9NYgi9oOUTVQ2gkqP1OJA9aawjCRwMJ7PRyKlBEpsdE/wFtu9/1ciGRtWSyACr2jTASZPQa+aHQh2qziacWd+iVmGIq0+l11nGG/GYU=");
        byte[] dBytes = Base64.decodeBase64("nyF45NssUzkdW3t7/tLxfENBKTN0TARh9ECfebqSoIR/9awxFrynQYnP+CSBw4jJcjHLzhR/4etsZkZZ9Cg3HhPA5pjVcI5kJct4kLjWM+ejZliZoV/KvpJN261VKKLTJMX64UeMiLAlb7mUNoNqKztgflxz5Dbad5hemvgwg50=");

        BigInteger modules = new BigInteger(1, modBytes);
        BigInteger exponent = new BigInteger(1, expBytes);
        BigInteger d = new BigInteger(1, dBytes);

        KeyFactory factory = KeyFactory.getInstance("RSA");
        Cipher cipher = Cipher.getInstance("RSA");
        String input = "test";

        RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(modules, exponent);
        PublicKey pubKey = factory.generatePublic(pubSpec);
        cipher.init(Cipher.ENCRYPT_MODE, pubKey);
        byte[] encrypted = cipher.doFinal(input.getBytes("UTF-8"));
        System.out.println(encrypted);
        System.out.println("encrypted: " + new String(encrypted));

        RSAPrivateKeySpec privSpec = new RSAPrivateKeySpec(modules, d);
        PrivateKey privKey = factory.generatePrivate(privSpec);
        cipher.init(Cipher.DECRYPT_MODE, privKey);
        byte[] decrypted = cipher.doFinal(encrypted);
        System.out.println("decrypted: " + new String(decrypted));
    }
}

Thursday, May 26, 2011

vi editor command


When you use Linux vi editor above commands will help you.

Tuesday, March 29, 2011

Java script to get list box text

When you want to get list box selected text from your application using java script use the following js code.

var w = document.getElementById('picklistid').selectedIndex;
var selected_text = document.getElementById('picklistid').options[w].text;

selected_text variable will be returned the combo box selected text.

Wednesday, March 9, 2011

Mysql Date

Some useful SQL commands to get dates in Mysql server.

select curdate() 3/10/2011
select curdate()-1 20110309
select curdate() - INTERVAL 1 DAY 3/9/2011