Welcome to Srini's blog

Friday, January 22, 2010

పుట్టిన రోజు శుభాకాంక్షలు కళ్యాణ్ (Happy B'day 'kalyan')

Today my frnd kalyan's B'day. Last night we(me,venki,sreekanth,bharat,sudheer,nagendra)
celebrated his b'day at Necklace road with very less bumps and some snaps. The lake view of the hussain sagar at night 12AM is very nice to see and we njoyed the view.
Today kalyan treated our group at McDonald's which is located nearby our office, We had a great time with all of our frnds. This is the first B'day from our group in 2010.
Once again MANY MANY HAPPY RETURNS OF THE DAY MY DEAR FRND and rock this year with full of josh and joy.
నువ్వు ఇంకా ఇలాంటి పుట్టినరోజులు ఎన్నో జరుపుకోవాలని కోరుకుంటూ --- శ్రీనివాస్
Some snaps here

Thursday, January 21, 2010

Difference between 'mstsc IP' & 'mstsc IP /console' cmds in RDP

'mstsc /console' cmd brings the physical console of the windows server's desktop by closing remote session if it is viewed by any other users, means u can get the server's desktop by logout the server's session.

'mstsc' brings new session of the server's desktop without dist rubbing the physical console of the RDP server, means through this cmd we can get the another session, like wise we can get as many sessions of RDP server(restricted by RDP server terminal license)

NOTE: Connecting to windows XP professional RDP server using 'mstsc' or 'mstsc /console' is same, because of win XP pro allows only one session at a time. So both cmds behavior is same.

Possible options for mstsc cmd are :
cmd is mstsc option
Options :
/v:[server[:port]] : The remote computer to connect to
/console : Connect to the console of a server (NT/XP)
/Admin : Connect to a session for administering the server(Vista/2008)
/f : Start in Full Screen mode
/w:width : Width of the RDP screen
/h:height: Height of the RDP screen
/span : Match the Remote Desktop width and height with the local virtual desktop, spanning across multiple monitors if necessary.(Vista/2008).
/public : Run Remote Desktop in public mode. (Vista/2008) In public mode, passwords and bitmaps are not cached.
/edit [ConnectionFile] : Open the RDP file for editing.ConnectionFile is the name of an RDP file for connection.
/migrate: Convert a legacy Client connection file into an .RDP file.

Note : The /console option only works when connecting to an Windows XP Professional or Windows Server 2003 computer.

Wednesday, January 20, 2010

Pongal tour to village

ముందుగా అందరకి సంక్రాంతి శుభాకాంక్షలు .... This pongal I went to my home village which is located near Tanuku, W.G. I enjoyed the vacation a lot with frnds sriram, sreekanth, suresh, Raju, Srinu...etc and family members. Myself and sriram met our old 10th classmates Kanakadurga, Durga rao, Swathi, Ram, Chamundi .. in our near by village and chitchatted some time with all of them. We just spent 20-25 min with them , but the feeling is really awesome.
Actually we planned a lot before coming to village, but ...

Thursday, December 31, 2009

Encrypt in JAVA and Decrypt in PHP & Encrypt in PHP and Decrypt in JAVA

Encrypt in JAVA and decrypt in PHP:

1. Encryption in JAVA:
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class Crypto {
//iv length should be 16 bytes
private String iv = "fedcba9876543210";
private String key = null;
private Cipher cipher = null;
private SecretKeySpec keySpec = null;
private IvParameterSpec ivSpec = null;

/**
* Constructor
*
* @throws Exception
*/
public Crypto(String key) throws Exception {
this.key = key;

// Make sure the key length should be 16
int len = this.key.length();
if(len < 16) {
int addSpaces = 16 - len;
for (int i = 0; i < addSpaces; i++) {
this.key = this.key + " ";
}
} else {
this.key = this.key.substring(0, 16);
}
this.keySpec = new SecretKeySpec(this.key.getBytes(), "AES");
this.ivSpec = new IvParameterSpec(iv.getBytes());
this.cipher = Cipher.getInstance("AES/CBC/NoPadding");
}

/**
* Bytes to Hexa conversion
*
* @param data
* @return
*/
public String bytesToHex(byte[] data) {
if (data == null) {
return null;
} else {
int len = data.length;
String str = "";
for (int i = 0; i < len; i++) {
if ((data[i] & 0xFF) < 16)
str = str + "0" + java.lang.Integer.toHexString(data[i] & 0xFF);
else
str = str + java.lang.Integer.toHexString(data[i] & 0xFF);
}
return str;
}
}

/** Encrpt the goven string
*
* @param plainData
* @throws Exception
*/
public String encrypt(String plainData) throws Exception {

// Make sure the plainData length should be multiple with 16
int len = plainData.length();
int q = len / 16;
int addSpaces = ((q + 1) * 16) - len;
for (int i = 0; i < addSpaces; i++) {
plainData = plainData + " ";
}

this.cipher.init(Cipher.ENCRYPT_MODE, this.keySpec, this.ivSpec);
byte[] encrypted = cipher.doFinal(plainData.getBytes());

return bytesToHex(encrypted);
}

public static void main(String[] args) throws Exception {
Crypto c = new Crypto("D4:6E:AC:3F:F0:BE");
String encrStr = c.encrypt("Hello World");
System.out.println("Encrypted Str :" + encrStr);
}
}
2. After run this program we will get encrypted str, Now decrypt this str using PHP
3. Decryption in PHP
$cipher = "rijndael-128";
$mode = "cbc";
$secret_key = "D4:6E:AC:3F:F0:BE";
//iv length should be 16 bytes
$iv = "fedcba9876543210";

// Make sure the key length should be 16 bytes
$key_len = strlen($secret_key);
if($key_len < 16 ){
$addS = 16 - $key_len;
for($i =0 ;$i < $addS; $i++){
$secret_key.=" ";
}
}else{
$secret_key = substr($secret_key, 0, 16);
}

$td = mcrypt_module_open($cipher, "", $mode, $iv);
mcrypt_generic_init($td, $secret_key, $iv);
$decrypted_text = mdecrypt_generic($td, hex2bin("444e6969a269829a3e59a86300614fc5"));
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
echo trim($decrypted_text);

function hex2bin($hexdata) {
$bindata="";
for ($i=0;$i $bindata.=chr(hexdec(substr($hexdata,$i,2)));
}
return $bindata;
}
?>
4. You will get decrypted str as "Hello World".



Encrypt in PHP and decrypt in JAVA:

1. Encryption in PHP:
$cipher = "rijndael-128";
$mode = "cbc";
$secret_key = "D4:6E:AC:3F:F0:BE";
//iv length should be 16 bytes
$iv = "fedcba9876543210";

// Make sure the key length should be 16 bytes
$key_len = strlen($secret_key);
if($key_len < 16 ){
$addS = 16 - $key_len;
for($i =0 ;$i < $addS; $i++){
$secret_key.=" ";
}
}else{
$secret_key = substr($secret_key, 0, 16);
}

$td = mcrypt_module_open($cipher, "", $mode, $iv);
mcrypt_generic_init($td, $secret_key, $iv);
$cyper_text = mcrypt_generic($td, "Hello World");
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
echo bin2hex($cyper_text);
?>
2. After run this program we will get encrypted str, Now decrypt this str using JAVA
3. Decryption in JAVA

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class Crypto {
//iv length should be 16 bytes
private String iv = "fedcba9876543210";
private String key = null;
private Cipher cipher = null;
private SecretKeySpec keySpec = null;
private IvParameterSpec ivSpec = null;

/**
* Constructor
*
* @throws Exception
*/
public Crypto(String key) throws Exception {
this.key = key;

// Make sure the key length should be 16
int len = this.key.length();
if(len < 16) {
int addSpaces = 16 - len;
for (int i = 0; i < addSpaces; i++) {
this.key = this.key + " ";
}
} else {
this.key = this.key.substring(0, 16);
}
this.keySpec = new SecretKeySpec(this.key.getBytes(), "AES");
this.ivSpec = new IvParameterSpec(iv.getBytes());
this.cipher = Cipher.getInstance("AES/CBC/NoPadding");
}

/**
* Hexa to Bytes conversion
*
* @param str
* @return
*/
public byte[] hexToBytes(String str) {
if (str == null) {
return null;
} else if (str.length() < 2) {
return null;
} else {
int len = str.length() / 2;
byte[] buffer = new byte[len];
for (int i = 0; i < len; i++) {
buffer[i] = (byte) Integer.parseInt(str.substring(i * 2, i * 2 + 2), 16);
}
return buffer;
}
}

/** Decrypt the given excrypted string
*
* @param encrStr
* @throws Exception
*/
public String decrypt(String encrData) throws Exception {
this.cipher.init(Cipher.DECRYPT_MODE, this.keySpec, this.ivSpec);
byte[] outText = this.cipher.doFinal(hexToBytes(encrData));

String decrData = new String(outText).trim();
return decrData;
}
public static void main(String[] args) throws Exception {
Crypto c = new Crypto("D4:6E:AC:3F:F0:BE");
String decrStr = c.decrypt("444e6969a269829a3e59a86300614fc5");
System.out.println("Decrypted Str :" + decrStr);
}
}
4. You will get decrypted str as "Hello World".

Tuesday, December 1, 2009

How to install native tomcat in LINUX

Steps to install native Tomcat in Linux :
1. First download latest native tomcat(tomcat-native-1.1.18-src.tar.gz) src from http://www.apache.org/dist/tomcat/tomcat-connectors/native/1.1.18/source/
2. Create temp location(eg. /tmp/tomcat) and copy downloded src into this folder
3. Run the following cmd to untar --> tar -xzvf tomcat-native-1.1.18-src.tar.gz
4. go to /tomcat-native-1.1.18-src/jni/native and run the cmd --> ./configure && make
5. It may propmt you an error as "apr is not located" and suggest give the cmd as --with-apr=APRDIR
The error because of apr is not installed in system. So now Install latest apr
Steps to Install apr :
6. Download latest apr(apr-1.3.9.tar.gz) src from
http://apache.opensourceresources.org/apr/
7. copy apr src into temp location(/tmp/tomcat).
8. Run the following cmd to untar --> tar -xzvf apr-1.3.9.tar.gz
9. Go to /apr-1.3.9 and run the cmd --> ./configure && make && make install.
So, apr installation completed. Now try to install native tomcat
10. go to /tomcat-native-1.1.18-src/jni/native and run the cmd --> ./configure && make
11. It may prompt you an error as "JDK is not located".
The error because of jdk is not installed in system(we need JDK to compile native
tomcat).So install latest JDK
Steps to install JDK :
12. Download latest JDK(jdk-6u17-linux-i586.bin) from http://java.sun.com/javase/downloads/index.jsp
13. Copy downloaded JDk into /usr/java(If location is not existed, create it and copy it).
14. Go to /usr/java and give permissions to jdk-6u17-linux-i586.bin file --> chmod 755 jdk-6u17-linux-i586.bin
15. install JDK using cmd --> ./jdk-6u17-linux-i586.bin
16. Follow the instructions carefully and install JDK.
17. If JDK installed successfully u can see 'jdk1.6.0_17' folder in /usr/java/.
18. Set java home path using cmds
i. JAVA_HOME="/usr/java/jdk1.6.0_17/"
ii. export JAVA_HOME.
So, JDK installation completed. Now try to install native tomcat.
19. go to /tomcat-native-1.1.18-src/jni/native and run the cmd --> ./configure && make.
20.Native tomcat installation completed successfully.

If you have any doubts/clarifications please let me know.