Encrypt password using JSP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Encrypt password using JSP

    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
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    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?

    [CODE=JAVA]

    <input type ="password" id="passowrd"> should mask the password on your JSP

    [/CODE]

    Please stay tuned for a better answer on this one, if this is not it.

    Dököll

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      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:
      Code:
      Cipher aesCipher;
          
          // Create the cipher
          aesCipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
      
      We use the generated aesKey from above to initialize the Cipher object for encryption: 
      
          // Initialize the cipher for encryption
          aesCipher.init(Cipher.ENCRYPT_MODE, aesKey);
      	  
          // Our cleartext
          byte[] cleartext = "This is just an example".getBytes();
      	  
          // Encrypt the cleartext
          byte[] ciphertext = aesCipher.doFinal(cleartext);
      
          // Initialize the same cipher for decryption
          aesCipher.init(Cipher.DECRYPT_MODE, aesKey);
            
          // Decrypt the ciphertext
          byte[] cleartext1 = aesCipher.doFinal(ciphertext);

      Comment

      Working...