By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,635 Members | 2,227 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,635 IT Pros & Developers. It's quick & easy.

Encrypt password using JSP

100+
P: 250
I have to develop a web application using JSP. I'm new to JSP. Could some one tell me how to encrypt password using JSP. I know php.
Oct 20 '09 #1
Share this Question
Share on Google+
2 Replies


Dököll
Expert 100+
P: 2,364
What do you mean by encrypt, do you mean mask it so noone knows what is being entered.

Are you using LDAP or is the password stored in a regular database?

Expand|Select|Wrap|Line Numbers
  1.  
  2. <input type ="password" id="passowrd"> should mask the password on your JSP
  3.  
  4.  
Please stay tuned for a better answer on this one, if this is not it.

Dököll
Nov 9 '09 #2

Expert 100+
P: 785
Just make a java class and call it in your jsp-page (or better struts-action).
If you are using this or older java versions than "JavaTM 2 SDK v 1.4", you can download the "JavaTM Cryptography Extension (JCE)".
In newer versions, these classes are already inside, see Java security classes

This is a code snippet randomly taken from the java API documentation:
Expand|Select|Wrap|Line Numbers
  1. Cipher aesCipher;
  2.  
  3.     // Create the cipher
  4.     aesCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
  5.  
  6. We use the generated aesKey from above to initialize the Cipher object for encryption: 
  7.  
  8.     // Initialize the cipher for encryption
  9.     aesCipher.init(Cipher.ENCRYPT_MODE, aesKey);
  10.  
  11.     // Our cleartext
  12.     byte[] cleartext = "This is just an example".getBytes();
  13.  
  14.     // Encrypt the cleartext
  15.     byte[] ciphertext = aesCipher.doFinal(cleartext);
  16.  
  17.     // Initialize the same cipher for decryption
  18.     aesCipher.init(Cipher.DECRYPT_MODE, aesKey);
  19.  
  20.     // Decrypt the ciphertext
  21.     byte[] cleartext1 = aesCipher.doFinal(ciphertext);
Nov 9 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.