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

   }

}









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 in php - PHP
password encryption in php  example of password encryption in php
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
Encryption and Decryption - Java Beginners
Encryption and Decryption  Hello sir, i need Password encryption and decryption program using java program. I dont know how to write the program... the source code of encyption and decryption using java. Thanking you... 
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
Create primary key using hibernate
Create primary key using hibernate  How to create primary key using hibernate?   The id element describes the primary key for the persistent class and how the key value is generated. ADS_TO_REPLACE_1   
array password - Java Beginners
array password  i had create a GUI of encryption program that used the array password. my question is can we do the password change program? i mean we change the older password with the new password
encryption and decryption - Java Beginners
encryption and decryption  i need files encryption and decryption program using java. but i dont know how to write the program.pls help me thank you so much  Hi Friend, Try the following code: import java.io.
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
How to create primary key using hibernate?
How to create primary key using hibernate?  Hi, How to create primary key using hibernate? Thanks
java password function
java password function  secret password function
decryption and encryption - Java Beginners
decryption and encryption  hi everyone. my question is that i have one problem which i have to solve and the issue is that i have to do the encryption and decryption thing there in my code, e.g if the user enters the abc the code
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
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
Maven dependency for com.codahale - aes-gcm-siv version 0.4.3 is released. Learn to use aes-gcm-siv version 0.4.3 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.4.3 ) in their Java project... 0.4.3 in Java projects. Follow the step by step tutorial for using the latest... and includes  com.codahale - aes-gcm-siv version 0.4.3 java library in your
Maven dependency for com.codahale - aes-gcm-siv version 0.4.0 is released. Learn to use aes-gcm-siv version 0.4.0 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.4.0 ) in their Java project... 0.4.0 in Java projects. Follow the step by step tutorial for using the latest... and includes  com.codahale - aes-gcm-siv version 0.4.0 java library in your
Maven dependency for com.codahale - aes-gcm-siv version 0.3.1 is released. Learn to use aes-gcm-siv version 0.3.1 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.3.1 ) in their Java project... 0.3.1 in Java projects. Follow the step by step tutorial for using the latest... and includes  com.codahale - aes-gcm-siv version 0.3.1 java library in your
Maven dependency for com.codahale - aes-gcm-siv version 0.3.0 is released. Learn to use aes-gcm-siv version 0.3.0 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.3.0 ) in their Java project... 0.3.0 in Java projects. Follow the step by step tutorial for using the latest... and includes  com.codahale - aes-gcm-siv version 0.3.0 java library in your
Maven dependency for com.codahale - aes-gcm-siv version 0.2.1 is released. Learn to use aes-gcm-siv version 0.2.1 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.2.1 ) in their Java project... 0.2.1 in Java projects. Follow the step by step tutorial for using the latest... and includes  com.codahale - aes-gcm-siv version 0.2.1 java library in your
Maven dependency for com.codahale - aes-gcm-siv version 0.1.0 is released. Learn to use aes-gcm-siv version 0.1.0 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.1.0 ) in their Java project... 0.1.0 in Java projects. Follow the step by step tutorial for using the latest... and includes  com.codahale - aes-gcm-siv version 0.1.0 java library in your
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... and includes  com.codahale - aes-gcm-siv version 0.4.2 java library in your
Maven dependency for com.codahale - aes-gcm-siv version 0.4.1 is released. Learn to use aes-gcm-siv version 0.4.1 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.4.1 ) in their Java project... 0.4.1 in Java projects. Follow the step by step tutorial for using the latest... and includes  com.codahale - aes-gcm-siv version 0.4.1 java library in your
Maven dependency for com.codahale - aes-gcm-siv version 0.2.2 is released. Learn to use aes-gcm-siv version 0.2.2 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.2.2 ) in their Java project... 0.2.2 in Java projects. Follow the step by step tutorial for using the latest... and includes  com.codahale - aes-gcm-siv version 0.2.2 java library in your
Maven dependency for com.codahale - aes-gcm-siv version 0.2.0 is released. Learn to use aes-gcm-siv version 0.2.0 in Maven based Java projects
this version ( com.codahale - aes-gcm-siv version 0.2.0 ) in their Java project... 0.2.0 in Java projects. Follow the step by step tutorial for using the latest... and includes  com.codahale - aes-gcm-siv version 0.2.0 java library in your
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
How can we encrypt the username and password using PHP?
How can we encrypt the username and password using PHP?  How can we encrypt the username and password using PHP
Password - Java Beginners
charecter just as typing password in E-mail.ID without using applet... can we do... = Box.createHorizontalBox(); rowTwo.add(new JLabel("Password")); rowTwo.add(new.... http://www.roseindia.net/java/example/java/swing/ Thanks
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
Softabar Password Manager
, is encrypted using AES encryption algorithm. Store accounts to server using Softabar Password Manager Server Storage... Softabar Password Manager   
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
login-password - Java Beginners
login-password  complete code of login-password form then how...; } if(theForm.password.value==""){ //please enter passward alert("Please enter Password...: Password
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
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
Maven dependency for com.braintreepayments - encryption version 2.1.0 is released. Learn to use encryption version 2.1.0 in Maven based Java projects
; com.braintreepayments - encryption version 2.1.0 in Java projects. Follow... and includes  com.braintreepayments - encryption version 2.1.0 java library... of encryption released The developers of   com.braintreepayments
Maven dependency for com.braintreepayments - encryption version 2.0.0 is released. Learn to use encryption version 2.0.0 in Maven based Java projects
; com.braintreepayments - encryption version 2.0.0 in Java projects. Follow... and includes  com.braintreepayments - encryption version 2.0.0 java library... of encryption released The developers of   com.braintreepayments
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
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
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... the input for password before creating a Java class we will create a database table
Using Password Controls

Ads