Java Encryption using AES with key password

Java Encryption using AES with key password

    /* 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);

      }

 }
View Answers

May 22, 2012 at 11:31 AM

  /* 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);

   }

}


May 22, 2012 at 11:31 AM

  /* 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);

   }

}

Ads









Related Tutorials/Questions & Answers:
Java Encryption using AES with key password
Java Encryption using AES with key password    /* AES alogrithm using password key */ /* developed by Nishanth Thomas Insolutions Global Pvt... */ /* AES alogrithm using password key */ /* developed by Nishanth Thomas
AES Decryption using key password
AES Decryption using key password    /* Decrypt using AES...;  /* Decrypt using AES with password */ /* developed by Nishanth..."; // put this as key in AES static SecretKeySpec key = new SecretKeySpec
Advertisements
AES encryption in J2ME
AES encryption in J2ME  Is it possible to do aes encryption in j2me
AES decryption in Java
-Decryption-using-key-password-.html    http://www.roseindia.net/answers/viewqa/Java-Beginners/26020-AES-Decryption-using-key-password-.html   ...AES decryption in Java   AES decryption in Java with password
Password encryption and decryption
Password encryption and decryption  Hello, I'm developing a system... users' password in the database so that I wouldnt know their password. Is there anyway that you could teach me how to encrypt the password and store
Change root password of MYSQL using Java
Change root password of MYSQL using Java In this tutorial, you will learn how to change the root password of MYSQL database using java code. For every..., the system administrator user is called root. You can also set the new password using
Connect a linux machine from linux using java program without password
Connect a linux machine from linux using java program without password  Connect a linux machine from linux using java program without password. Can anyone help me
encrypt the username and password using PHP
encrypt the username and password using PHP  How can we encrypt the username and password using PHP?   Hi friends, You can use the MySQL PASSWORD() function to encrypt username and password. For example, INSERT
How to create primary key using hibernate?
How to create primary key using hibernate?  Hi, How to create primary key using hibernate? Thanks
Encryption Decryption In Scriptlets/Java
Encryption Decryption In Scriptlets/Java  I have this code in my scriptlet, when I use the Encryption code to encrypt my data it executes... DESede key".getBytes(); DESedeKeySpec spec = new DESedeKeySpec(encryptKey
java password function
java password function  secret password function
How to handle the text using Key Listener Interface
to handle the text using the key events on the Java Awt component. All the key events... How to handle the text using Key Listener Interface... are going to show you how to display the text of textField1 on the text field2 on key
code for password strength using jsp-servlet
code for password strength using jsp-servlet  hi.............. plz help me to give code for password strength using jsp-servlet for implementation in my project as soon as possible because i want to show this functionality in my
java key value pair
java key value pair  Hi, How to save the java key value pair in Java? Thanks   Hi, You can use the Hashtable for this purpose. Check the tutorial Creating a Hash Table. Thanks
can any one give the frogort password code using jsp,
can any one give the frogort password code using jsp,  plz give the code for frogot password
Version of com.amazonaws>aws-dynamodb-encryption-java dependency
List of Version of com.amazonaws>aws-dynamodb-encryption-java dependency
Version of com.amazonaws>aws-encryption-sdk-java dependency
List of Version of com.amazonaws>aws-encryption-sdk-java dependency
Maven dependency for com.codahale - aes-gcm-siv version 0.4.2 is released. Learn to use aes-gcm-siv version 0.4.2 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.4.2 ) in their Java project... 0.4.2 in Java projects. Follow the step by step tutorial for using the latest...; com.codahale - aes-gcm-siv version 0.4.2 java library in your project. Now
How to supress displaying username and password in Java Web Start 10.21.2.11 Using JRE version 1.7.0_21-b11 Java HotSpot(TM) Client VM
How to supress displaying username and password in Java Web Start 10.21.2.11 Using JRE version 1.7.0_21-b11 Java HotSpot(TM) Client VM  I have installed Java 1.7.21 from java 1.6. I am observing username and password (match
how to check username & password from database using jsp
how to check username & password from database using jsp  Hello, I have created 1 html page which contain username, password & submit button. in my oracle10G database already contain table name admin which has name, password
registration key - Java Beginners
registration key  I want the serial key for JCreator Pro 4.50. I lost it. If any body has it please send
Access denied for user 'abc'@'xxxx' (using password: YES)
Access denied for user 'abc'@'xxxx' (using password: YES)  I have tested my code on local machine DB, its working correctly.. But when i shifted it to server DB using URL, Username and password.. i got this error .. How can i
Looking for change password in iphone application sdk using sqlite
Looking for change password in iphone application sdk using sqlite  i am trying to change old password in my iphone application my code is below...) == SQLITE_OK) { NSString *querySQL = [NSString stringWithFormat: @"SELECT password
Password
Password  make a program which ask ask the username and password * in this format. in C language
Maven Dependency aws-encryption-sdk-java >> 0.0.1
You should include the dependency code given in this page to add Maven Dependency of com.amazonaws >> aws-encryption-sdk-java version0.0.1 in your project
Maven Dependency aws-dynamodb-encryption-java >> 1.11.0
You should include the dependency code given in this page to add Maven Dependency of com.amazonaws >> aws-dynamodb-encryption-java version1.11.0 in your project
Java Password Field
Java Password Field In this section we will discuss how to use password field in Java. To create a password field in Java Swing JPasswordField is used..., `password` varchar(15) DEFAULT NULL, PRIMARY KEY (`name
ModuleNotFoundError: No module named 'aes'
ModuleNotFoundError: No module named 'aes'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'aes' How to remove the ModuleNotFoundError: No module named 'aes' error
Using Password Controls
how to use foreign key in java
how to use foreign key in java  I have two tables in my MySQL..., first name varchar(10), primary key(id) ) CREATE TABLE table2 ( id_fk int, last varchar(30), CONSTRAINT fkid FOREIGN KEY(idfk) REFERENCES table1(id) ON DELETE
How to set a microsoft word document PASSWORD by using Visual Basic 2008 express?
How to set a microsoft word document PASSWORD by using Visual Basic 2008 express?   How to set a microsoft word document PASSWORD by using Visual Basic 2008 express

Ads