/* AES alogrithm using password key */
/* developed by Nishanth Thomas Insolutions Global Pvt Ltd Bangalore */
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Encoder;
/* Mode = CipherMode.CBC,-( Cipher-block chaining)
Padding = PaddingMode.PKCS7 or PKCS5,
KeySize = 128,
BlockSize = 128,
Key = keyBytes - password,
IV = keyBytes - password*/
public class testencrypt {
Cipher cipher;
// Input encrypted String
static String input = "Hi This is my String";
// password for encryption
final static String strPassword = "password12345678";
// put this as key in AES
static SecretKeySpec key = new SecretKeySpec(strPassword.getBytes(), "AES");
public static void main(String args []) throws Exception{
// Parameter specific algorithm
AlgorithmParameterSpec paramSpec = new IvParameterSpec(strPassword.getBytes());
//Whatever you want to encrypt/decrypt
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
// You can use ENCRYPT_MODE (ENCRYPTunderscoreMODE) or DECRYPT_MODE (DECRYPT underscore MODE)
cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
// encrypt data
byte[] ecrypted = cipher.doFinal(input.getBytes());
// encode data using standard encoder
String output = new BASE64Encoder().encode(ecrypted);
System.out.println("Orginal tring: " + input);
System.out.println("Encripted string: " + output);
}
}
/* AES encryption alogrithm in JAVA */
/* AES alogrithm using password key */
/* developed by Nishanth Thomas Insolutions Global Pvt Ltd Bangalore */
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Encoder;
/* Mode = CipherMode.CBC,-( Cipher-block chaining)
Padding = PaddingMode.PKCS7 or PKCS5,
KeySize = 128,
BlockSize = 128,
Key = keyBytes - password,
IV = keyBytes - password*/
public class testencrypt {
Cipher cipher;
// Input encrypted String
static String input = "Hi This is my String";
// password for encryption
final static String strPassword = "password12345678";
// put this as key in AES
static SecretKeySpec key = new SecretKeySpec(strPassword.getBytes(), "AES");
public static void main(String args []) throws Exception{
// Parameter specific algorithm
AlgorithmParameterSpec paramSpec = new IvParameterSpec(strPassword.getBytes());
//Whatever you want to encrypt/decrypt
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
// You can use ENCRYPT_MODE (ENCRYPTunderscoreMODE) or DECRYPT_MODE (DECRYPT underscore MODE)
cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
// encrypt data
byte[] ecrypted = cipher.doFinal(input.getBytes());
// encode data using standard encoder
String output = new BASE64Encoder().encode(ecrypted);
System.out.println("Orginal tring: " + input);
System.out.println("Encripted string: " + output);
}
}
/* AES encryption alogrithm in JAVA */
/* AES alogrithm using password key */
/* developed by Nishanth Thomas Insolutions Global Pvt Ltd Bangalore */
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Encoder;
/* Mode = CipherMode.CBC,-( Cipher-block chaining)
Padding = PaddingMode.PKCS7 or PKCS5,
KeySize = 128,
BlockSize = 128,
Key = keyBytes - password,
IV = keyBytes - password*/
public class testencrypt {
Cipher cipher;
// Input encrypted String
static String input = "Hi This is my String";
// password for encryption
final static String strPassword = "password12345678";
// put this as key in AES
static SecretKeySpec key = new SecretKeySpec(strPassword.getBytes(), "AES");
public static void main(String args []) throws Exception{
// Parameter specific algorithm
AlgorithmParameterSpec paramSpec = new IvParameterSpec(strPassword.getBytes());
//Whatever you want to encrypt/decrypt
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
// You can use ENCRYPT_MODE (ENCRYPTunderscoreMODE) or DECRYPT_MODE (DECRYPT underscore MODE)
cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
// encrypt data
byte[] ecrypted = cipher.doFinal(input.getBytes());
// encode data using standard encoder
String output = new BASE64Encoder().encode(ecrypted);
System.out.println("Orginal tring: " + input);
System.out.println("Encripted string: " + output);
}
}