Wednesday, July 03, 2013

Writing Resume for Software Company

Fresh graduate has to write resume to represent himself/herself as a potential candidate for a job. Initially it seems a easy task to do , yes it is easy in terms of typing in a key board by enough tricky.

To Do or Not To Do :
-Write your objective as simple as possible , i recommend one - two lines .
-Must use formal English and use simple words.
-Do not put your personal information : such as --- race , moms name etc.
-Focus on your achievement rather responsibility in previous position
-Put only those technical skill you know properly , never put something super special but you have no idea with that.
-Highlight your academic performance.
-In top  : Write name , address and contact number properly
-Two page is enough to represent you , may up to three page , but not more then that . All are busy in these day they don't have much time to read your long story .
-Always use PDF format while sending resume.-Send your resume to your known ones and ask for review and comments on that , this will help you to overcome silly mistake.
-Hey! you resume if not a polish diamond , share it with others , don't be poor minded.
-Highlight research experience , if you have any but not mandatory .
-



Monday, July 01, 2013

Example of Advanced Encryption Standard (AES) using JAVA

Example of AES using JAVA : 

Note : For base64 related method visit this post.
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;



/**
 * 
 * @author : ThinkTank
 * 
 * 
 */


public class AESEncryption {
 private KeyGenerator keyGenerator;
 private SecureRandom secureRandom;
 private byte[] randomBytes = new byte[100];
 private byte[] encryptedData = new byte[20000];
 private byte[] decryptedData = new byte[20000];
 private String encryptedDataAsBase64String;
 private SecretKey secretKey;
 private SecretKeySpec secretKeySpec;
 private Cipher cipher;
 private String originalData;



 /**
  * This method will encrypt data as our desired level
  * 
  * @param data data to be encrypted
  * @param encryptionLevel level of encryption
  * @param secureRandomSeed seed value 
  * @return encrypted string
  */
 public String encrypt(byte[] data,int encryptionLevel,int secureRandomSeed) {
  try {
   keyGenerator = KeyGenerator.getInstance("AES");
   keyGenerator.init(encryptionLevel);

   secureRandom = SecureRandom.getInstance("SHA1PRNG", "SUN");
   secureRandom.setSeed(secureRandomSeed);

   secureRandom.nextBytes(randomBytes);

   secretKey = keyGenerator.generateKey();
   byte[] primaryEncodedKey = secretKey.getEncoded();

   secretKeySpec = new SecretKeySpec(primaryEncodedKey, "AES");

   cipher = Cipher.getInstance("AES");
   cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);

   encryptedData = cipher.doFinal(data);

   encryptedDataAsBase64String = Util.byteToBase64(encryptedData);

  } catch (NoSuchProviderException e) {
   e.getStackTrace();
  } catch (NoSuchAlgorithmException e) {
   e.getStackTrace();
  } catch (NoSuchPaddingException e) {
   e.getStackTrace();
  } catch (InvalidKeyException e) {
   e.getStackTrace();
  } catch (BadPaddingException e) {
   e.getStackTrace();
  } catch (IllegalBlockSizeException e) {
   e.getStackTrace();
  }
  return encryptedDataAsBase64String;
 }

 /**
  * This method will return decrypted data
  *  
  * @return decrypted data as string 
  */
 public String decrypt(byte[] encryptedData) {
  
  try {
   cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
   decryptedData = cipher.doFinal(encryptedData);
   originalData = new String(decryptedData);
  } catch (InvalidKeyException e) {
   e.getStackTrace();
  } catch (IllegalBlockSizeException e) {
   e.getStackTrace();
  } catch (BadPaddingException e) {
   e.getStackTrace();
  }
  return originalData;
 }
}


Ready to use One way Digest util class in JAVA or Example of SHA-512 Digest Using Java



Ready to use One way digest Java Class


Note : For base64 related method visit this post :


import java.security.MessageDigest;
import java.security.SecureRandom;


/**
 * 
 * @author : ThinkTank
 * 
 */



public class PasswordDigest {

/**
 * This method will compute hash as string for given password
 * 
 * @param salt salt value
 * @param passDigest password digest
 * @param password password which will digested 
 * @param iterationNumber number of iteration
 * @return password hash value
 * @throws Exception
 */
public static String recomputeHash(byte[] salt, String passDigest,String password,int iterationNumber) throws Exception {
 byte regeneratedHash[] = PasswordDigest.getHash(iterationNumber, password, salt);
 return Util.byteToBase64(regeneratedHash);
}

/**
 * @param iterationNumber
 * @param password
 * @param salt
 * @return hash digest as byte array
 * @throws Exception
 */
public static byte[] getHash(int iterationNumber, String password, byte[] salt) throws Exception {
 MessageDigest digest = MessageDigest.getInstance("SHA-512");
 digest.reset();
 digest.update(salt);
 byte[] input = digest.digest(password.getBytes("UTF-8"));
 for (int i = 0; i < iterationNumber; i++) {
  digest.reset();
  input = digest.digest(input);
 }
 return input;
}

/**
 * This method will generate salt value and return it as byte array
 * 
 * @return salt value as byte array
 * @throws Exception
 */
public static byte[] getSalt() throws Exception {
 SecureRandom secureRandom;
 byte[] bSalt = new byte[8];
 secureRandom = SecureRandom.getInstance("SHA1PRNG","SUN");
 secureRandom.nextBytes(bSalt);
 return bSalt;
}

}

Convert Base64 to Byte and Byte to Base64 in Java


Simple Ready to use utility class to convert : base64 -> byte and byte -> base64
import org.apache.commons.codec.binary.Base64;


public class Util {

 /**
  * 
  * This method take base64 type string as input and
  * convert it to byte[] array
  *  
  * @param data base64 type string
  * @return byte array
  * @throws Exception
  *  
  */

 @SuppressWarnings("unused")
 public static byte[] base64ToByte(String data) throws Exception {
  Base64 base64 = new Base64();
  return Base64.decodeBase64(data);
 }

 /**
  * This method take byte array as input and
  * convert it to base64 string
  * 
  * @param data byte array
  * @return base64 string
  * 
  */
 @SuppressWarnings("static-access")
 public static String byteToBase64(byte[] data) {
  Base64 base64 = new Base64();
  return base64.encodeBase64String(data);
 }

}