Connecting Tech Pros Worldwide Help | Site Map

Encrypt password using JSP

Familiar Sight
 
Join Date: Jan 2008
Posts: 198
#1: 4 Weeks Ago
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.
Dököll's Avatar
Moderator
 
Join Date: Nov 2006
Location: Upstate NY - US
Posts: 2,267
#2: 2 Weeks Ago

re: Encrypt password using JSP


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
Expert
 
Join Date: Nov 2007
Location: Germany
Posts: 294
#3: 2 Weeks Ago

re: Encrypt password using JSP


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